#!/bin/bash
while read line; do
grep "$line" file1.txt
if [ $status -eq 1]
echo "$line" >> f2.txt
done < f3.txt
当我执行包含上述脚本的shell脚本时。我收到以下错误:
./test.sh: line 7: syntax error near unexpected token `done'
./test.sh: line 7: `done < f3.txt'
任何人都可以帮助我,为什么我会收到此错误?
答案 0 :(得分:2)
#!/bin/bash
while read line; do
grep "$line" file1.txt
if [ $? -eq 1 ]; then
echo "$line" >> f2.txt
fi
done < f3.txt
您的代码中存在大量错误。
答案 1 :(得分:2)
您的脚本可以简化为:
#!/bin/bash
while read -r line; do
grep -q "$line" file1.txt || echo "$line" >> f2.txt
done < f3.txt
此echo "$line" >> f2.txt
仅在grep -q
返回非零状态时才会执行。