Subject: Re: /bin/sh bug or not?
To: None <>
From: Chet Ramey <chet@odin.INS.CWRU.Edu>
List: current-users
Date: 05/11/1995 10:37:28
> > Well, I have run across something else that looks suspicious in NetBSD
> > sh and I wanted to run it past you. Take the expression:
> > 
> >         i=`false`
> > 
> > Under AIX ksh, this expression will set return code to 1.
> > Under SunOS sh, this expression will set return code to 255.
> > Under SunOS bash, this expression will set return code to 255.

Which version of bash?  And which version of sh?

odin(2)$ i=`false`
odin(2)$ echo $?
odin(2)$ echo $BASH_VERSION
odin(2)$ uname -a
SunOS odin 4.1.2 13 sun4m
odin(2)$ sh
${HOST}($SHLVL)\$ i=`false`
${HOST}($SHLVL)\$ echo $?

> > Under NetBSD sh, the expression will set the return code to 0 because
> > it treats variable assignment as one transaction and the execution
> > of the builtin function false as another transaction. As it turns out,
> > the variable assignment happens last so it's return value is what is
> > trapped and returned by the shell in $?.
> This still happens in -current as of Mon May 8.  Does any standard
> mandate this behaviour?

According to Posix.2, the netbsd sh is wrong.  Posix.2 says that any
command line that does not contain a command to be executed after
expansion should return the status of any command substitution
performed while expanding the command, or zero if no command
subsitution occurs. 

``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu