我写了一个从fil
读取的shell脚本file="a.txt"
while read line
do
line1 = $(awk '{if($1 == "Only")print"$3;"}' "$line")
echo "$line1"
line1 = $(sed '$s/.$//' "$line1")
line2 = $(awk '{if($1 == "Only")print"$4";}' "$line")
line3 = $(sed -r 's/^.{3}//' "$line1line2")
done <"$file"
我一直收到此错误a.sh: 5: a.sh: line1: not found
。我做错了什么?
答案 0 :(得分:4)
赋值运算符前后不允许有空格。将您的代码更改为:
line1=$(awk '{if($1 == "Only")print"$3;"}' "$line")
echo "$line1"
line1=$(sed '$s/.$//' "$line1")
line2=$(awk '{if($1 == "Only")print"$4";}' "$line")
line3=$(sed -r 's/^.{3}//' "$line1line2")
有关详细信息,请参阅Variable Assignment。