From simonmar@sm.dnsalias.com  Tue May 17 16:20:42 2005
Return-Path: <simonmar@sm.dnsalias.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8597316A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 May 2005 16:20:42 +0000 (GMT)
Received: from mta05-winn.mailhost.ntl.com (smtpout15.mailhost.ntl.com [212.250.162.15])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5E70543D9E
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 May 2005 16:20:41 +0000 (GMT)
	(envelope-from simonmar@sm.dnsalias.com)
Received: from aamta07-winn.mailhost.ntl.com ([212.250.162.8])
          by mta05-winn.mailhost.ntl.com with ESMTP
          id <20050517162034.RARY23015.mta05-winn.mailhost.ntl.com@aamta07-winn.mailhost.ntl.com>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Tue, 17 May 2005 17:20:34 +0100
Received: from sm.dnsalias.com ([80.2.244.186])
          by aamta07-winn.mailhost.ntl.com with ESMTP
          id <20050517162034.WYHF1399.aamta07-winn.mailhost.ntl.com@sm.dnsalias.com>
          for <FreeBSD-gnats-submit@freebsd.org>;
          Tue, 17 May 2005 17:20:34 +0100
Received: from sm.dnsalias.com (localhost [127.0.0.1])
	by sm.dnsalias.com (8.13.1/8.12.6) with ESMTP id j4HGKV1J034639
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 May 2005 17:20:31 +0100 (BST)
	(envelope-from simonmar@sm.dnsalias.com)
Received: (from simonmar@localhost)
	by sm.dnsalias.com (8.13.1/8.12.6/Submit) id j4HGKVLK034638;
	Tue, 17 May 2005 17:20:31 +0100 (BST)
Message-Id: <200505171620.j4HGKVLK034638@sm.dnsalias.com>
Date: Tue, 17 May 2005 17:20:31 +0100 (BST)
From: Simon Marlow <simonmar@gmail.com>
Reply-To: Simon Marlow <simonmar@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /bin/sh -e bug
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         81165
>Category:       bin
>Synopsis:       /bin/sh -e bug
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 17 16:30:00 GMT 2005
>Closed-Date:    Sat Sep 10 10:59:10 GMT 2005
>Last-Modified:  Sat Sep 10 10:59:10 GMT 2005
>Originator:     Simon Marlow
>Release:        FreeBSD 4.11-STABLE i386
>Organization:
>Environment:
System: FreeBSD sm.dnsalias.com 4.11-STABLE FreeBSD 4.11-STABLE #43: Sun Jan 23 00:11:26 GMT 2005 simonm@sm.dnsalias.com:/usr/src/sys/compile/RACHEL i386
>Description:

There is a bug in ash's handling of the -e flag.  See the example below.

>How-To-Repeat:

$ 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.

>Fix:

unknown.

>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@ceid.upatras.gr>
To: Simon Marlow <simonmar@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: bin/81165: /bin/sh -e bug
Date: Tue, 17 May 2005 21:34:45 +0300

 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.
 
 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)?
 

From: Parv <parv@pair.com>
To: Simon Marlow <simonmar@gmail.com>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: bin/81165: /bin/sh -e bug
Date: Tue, 17 May 2005 15:53:07 -0400

 in message <200505171620.j4HGKVLK034638@sm.dnsalias.com>,
 wrote Simon Marlow thusly...
 >
 > There is a bug in ash's handling of the -e flag.  See the example below.
 > 
 > >How-To-Repeat:
 > 
 > $ 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.
 
 Just a data point ... "test succeeded" is printed by /bin/sh of
 FreeBSD 5.3-p13, ksh93 20050202, & bash 3.0.16_1.
 
 
   - Parv
 
 -- 
 

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
State-Changed-From-To: open->patched 
State-Changed-By: stefanf 
State-Changed-When: Sat Sep 10 10:14:02 GMT 2005 
State-Changed-Why:  
Mark as patched because this bug exists only in RELENG_4.  Personally I 
don't want to touch sh in RELENG_4, so maybe the PR should just be closed. 
Simon, is updating to RELENG_{5,6} an option for you? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81165 
State-Changed-From-To: patched->closed 
State-Changed-By: stefanf 
State-Changed-When: Sat Sep 10 10:57:08 GMT 2005 
State-Changed-Why:  
Originator agrees that the report can be closed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81165 
>Unformatted:
