我正在讀取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