我正在读取test.txt文件。格式:Bash:逐行读取文件,拆分行,作为命令行传递arg
79033d0135a21e45c60e283785f5914b
dde8d97a40cd22667ccb3ca972197586
4fd5ea73cd51db256384fb3333b0eb3d
我正在读由线和分割该文件中的行为(例如第1行:79 03 3D 01 35 A2 1E 45 C6 0E 28 37 85 F5 91 4B)
的bash脚本是:
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
a="$line" | cut -c1-2
b="$line" | cut -c3-4
c="$line" | cut -c5-6
d="$line" | cut -c7-8
e="$line" | cut -c9-10
f="$line" | cut -c11-12
g="$line" | cut -c13-14
h="$line" | cut -c15-16
i="$line" | cut -c17-18
j="$line" | cut -c19-20
k="$line" | cut -c21-22
l="$line" | cut -c23-24
m="$line" | cut -c25-26
n="$line" | cut -c27-28
o="$line" | cut -c29-30
p="$line" | cut -c31-32
#./a.out "$a" "$b" "$c" "$d" "$e" "$f" "$g" "$h" "$i" "$j" "$k" "$l" "$m" "$n" "$o" "$p"
echo "$line"
echo "$a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p"
done < test_10.txt
现在我只是试图打印变量。我打算在稍后将它们作为命令行参数传递给我的C++程序。
问题是,我无法打印变量。当然,我的C++程序也不能接受参数。
我在做什么错?
嗨,谢谢!你能解释第二个解决方案吗?我的意思是匿名管道是什么意思? – algoProg
@algoProg'|'被称为匿名管道,必须使用'echo'$ line“| cut -c1-2',你需要一个额外的进程'echo',而第二个不需要的管道''''''由shell在内部处理。 – heemayl
清除!谢谢! – algoProg