Shell中的变量声明

时间:2014-07-05 16:20:18

标签: bash shell

我写了一个从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。我做错了什么?

1 个答案:

答案 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