From owner-freebsd-bugs@FreeBSD.ORG Tue May 17 20:30:23 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 12B7716A4CE for ; Tue, 17 May 2005 20:30:23 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id CAEE843DD5 for ; Tue, 17 May 2005 20:30:22 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j4HKU61J047885 for ; Tue, 17 May 2005 20:30:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j4HKU6oX047882; Tue, 17 May 2005 20:30:06 GMT (envelope-from gnats) Date: Tue, 17 May 2005 20:30:06 GMT Message-Id: <200505172030.j4HKU6oX047882@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Simon Marlow Subject: Re: bin/81165: /bin/sh -e bug X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Simon Marlow List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2005 20:30:23 -0000 The following reply was made to PR bin/81165; it has been noted by GNATS. From: Simon Marlow To: Giorgos Keramidas 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 wrote: > On 2005-05-17 17:20, Simon Marlow 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