- 论坛徽章:
- 0
|
我在SCO OpenServer 5.0.6上写了个shell,总有问题,但自己不知道怎么解决
#!/bin/sh
while read LINE
do
flag ="0"
file1 = `echo "$LINE"|awk -F ' ' '{print $1}'`
while read LINE1
do
file2 = `echo "$LINE1"|awk -F ' ' '{print $1}'`
if [ "$file1" = "$file2" ]
then
flag="1"
echo $flag
break
fi
done </tmp/2.txt
echo $falg
if [ "$flag" -ne "1"]
then
echo "$file1 not found in 2.txt"
else
echo "$file1 Have found in 2.txt"
fi
done </tmp/1.txt
以上就是shell的原码
/tmp/1.txt 和 /tmp/2.txt相同,就是一行记录
记录内容是: 5111
在运行后发现,flag 是在第二个while 中由于$file1 = $file2 所以flag = "1"但在break后,发现flag的值还是"0";
如果将while .... done
修改成 for loop in `cat /tmp/1.txt"的方式就正确了
请问两者的差别是什么?谢谢 |
|