Date: Tue, 17 May 2005 20:30:06 GMT From: Simon Marlow <simonmar@gmail.com> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/81165: /bin/sh -e bug Message-ID: <200505172030.j4HKU6oX047882@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/81165; it has been noted by GNATS. From: Simon Marlow <simonmar@gmail.com> To: Giorgos Keramidas <keramida@ceid.upatras.gr> Cc: bug-followup@freebsd.org Subject: Re: bin/81165: /bin/sh -e bug Date: Tue, 17 May 2005 21:26:34 +0100 On 5/17/05, Giorgos Keramidas <keramida@ceid.upatras.gr> wrote: > On 2005-05-17 17:20, Simon Marlow <simonmar@gmail.com> wrote: > > There is a bug in ash's handling of the -e flag. See the example > > below. > > > > $ cat >test.sh > > if true; then > > false && true > > fi > > echo "test succeeded" > > $ /bin/sh -e test.sh > > zsh: 34546 exit 1 /bin/sh -e test.sh > > $ bash -e test.sh > > test succeeded > > > > Bash works correctly. If the 'if' statement is removed, ash also > > works correctly. >=20 > Are you sure what bash does is correct? What do the standards say about > indermediate commands that fail and the correct behavior of the "shell" > (i.e. the "false" command in there)? Yes, I'm sure. The /bin/sh manpage says: -e errexit Exit immediately if any untested command fails in non-interact= ive mode. The exit status of a command is considered to be explic= - itly tested if the command is used to control an if, elif, whi= le, or until; or if the command is the left hand operand of an ``&= &'' or ``||'' operator. and (clearer, IMO), the Single Unix Spec: -e When this option is on, if a simple command fails for any of the reasons listed in Consequences of Shell Errors or returns an exit status value >0, and is not part of the compound list following a while, until or if keyword, and is not a part of an AND or OR list, and is not a pipeline preceded by the "!" reserved word, then the shell will immediately exit. so the upshot is that the command false && X should not cause the script to exit when the -e switch is on (it doesn't matter what X is). You can easily see that the behaviour of /bin/sh is strange, because in this case if true; then E; fi does not behave in the same way as just E. However, it appears that /bin/sh in FreeBSD 5.3 is working correctly. Cheers, Simon
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200505172030.j4HKU6oX047882>