Korn shell behaviour in AIX

Hi,

Consider the code snippet below:

 
fun()
{
while read x
do
echo $x
done < somefile_that_does_not_exists
}
 
fun
echo I am here

Korn shell on HPUX prints the message "I am here", while the behaviour is different on AIX korn shell. We do not get the message on AIX. Any clues on how to get a similar behaviour.

Thanks in Advance.

It works for me if I execute it this way:

./testcode

This was done on AIX 5.2

Yes, well I have it running on HP-UX with a file not found error then the "I am here" bit, but on AIX 6.1, AIX 5.1 (please don't laugh yet) and ...... AIX 4.3.3 :o I just get the file not found error and the script aborts.

I also inserted

 #!/bin/ksh

as the first line to be sure, but no change. I presume that this is suddenly a good reason to use cat!!!

If I write this in my natural style as

#!/bin/ksh
fun()
{
cat some_file_that_does_not_exist | while read x
do
echo $x
done 
}

fun
echo I am here

...it works fine on AIX too.

Can anyone explain the mismatch?

.... and here's me battling my instincts to avoid a useless use of cat such as cat $file | while code. :rolleyes:

Robin
Liverpool/Blackburn
UK

Seems a bit sloppy to me. Wouldn't it just be better to check if the file exists first?

"cat" must not be letting ksh exit if the file is not found. But with the file redirected to a while loop, the shell exits in AIX.

Any ideas if a flag/set option with ksh works on AIX?

I would do what Scott suggested and check to see if the file exist. If it does then perform your commands if not then exit the script.