There no single explanation and the main problem is not whether the file exists. It is what shell is being used. Consider this:
Code:
$ cat fcheck
#!/bin/sh
FLAG=0;
cat filename | while read data
do
echo "data=$data"
FLAG=1;
done
echo $FLAG
Bash
Code:
$ bash fcheck
data=line1
data=line2
0
Bourne:
Code:
$ sh fcheck
data=line1
data=line2
0
Korn:
Code:
$ ksh fcheck
data=line1
data=line2
1
So for sh, the behavior is as expected.
|