[Gllug] Bizarre shell behaviour

Ian Northeast ian at house-from-hell.demon.co.uk
Fri Nov 7 20:26:56 UTC 2003


David Damerell wrote:
> On Friday, 7 Nov 2003, Tethys wrote:
> 
>>Take the following shell script. Run it:
>>Assuming /etc/group isn't empty (which it isn't), the script should
>>echo 1, right? Well the answer is, it depends on the shell. Under
>>bash, pdksh and genuine ksh, yes, it does. But under Bourne shell,
>>it varies. Under AIX and OpenBSD, sure enough it echoes a 1. But
>>under Solaris and Tru64, it echoes 0 instead.
> 
> 
> Not under Solaris 2.8 here it doesn't. I can only make it do that by
> using a file I don't have read permission to (but how could one not
> have read permission to /etc/group ?)

On Solaris 8 and 9 here it echoes 0. My Solaris 8 is the Intel version 
but this shouldn't make any difference. I have both flavours of 9. It 
echoes 0 in Bourne shell on AIX too - note that on AIX /bin/sh is ksh, 
the Bourne shell is /bin/bsh. /bin/sh is also ksh (pdksh) on OpenBSD, 
which does not appear to possess a Bourne shell (I don't think there's a 
public domain version - the OpenBSD 3.1 man page for sh says "KSH(1) sh 
- public domain Bourne shell" which is a bit confusing).

So as far as I can see, it always echoes 0 in Bourne, and 1 in ksh and 
bash. At least this is reasonably consistent.

I remember a similar construct showing up different behaviour in the 
commercial ksh and pdksh which was a pain as the script in question was 
supposed to work on both AIX and Linux. I can't remember the exact 
details, but it was definitely a loop with redirected input.

Regards, Ian









-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list