The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 05-23-2008
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
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.