NetBSD Problem Report #17514

Received: (qmail 23717 invoked by uid 605); 8 Jul 2002 02:22:57 -0000
Message-Id: <200207080222.g682Me718259@rocinante.zlz.net>
Date: Sun, 7 Jul 2002 22:22:40 -0400 (EDT)
From: dbj@netbsd.org
Sender: gnats-bugs-owner@netbsd.org
Reply-To: dbj@netbsd.org
To: gnats-bugs@gnats.netbsd.org
Cc: dbj@netbsd.org
Subject: /bin/sh `set -e' does not exit on command not found
X-Send-Pr-Version: 3.95

>Number:         17514
>Category:       bin
>Synopsis:       /bin/sh `set -e' does not exit on command not found
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 08 02:23:00 +0000 2002
>Closed-Date:    Sun Feb 21 17:49:58 +0000 2016
>Last-Modified:  Sun Feb 21 17:49:58 +0000 2016
>Originator:     Darrin B. Jewell
>Release:        NetBSD 1.6_BETA2 via cvs ~20020616T2139Z on netbsd-1-6 branch
>Organization:
>Environment:
System: NetBSD quiteria 1.6_BETA2 NetBSD 1.6_BETA2 (QUITERIA) #13: Thu Jun 20 17:05:07 EDT 2002 dbj@quiteria:/usr/src/sys/arch/macppc/compile/QUITERIA macppc
Architecture: powerpc
Machine: macppc
>Description:
A /bin/sh script that uses `set -e' does not exit
when it cannot find a command in my path.

the testme1.sh case below works incorrectly
but the testme2.sh case below with an absolute
path works as I expect.

Notice also that the error reporting style is
different between the two.

>How-To-Repeat:

$ sh ./testme1.sh
this_command_should_not_be_found: not found
Should not still be running
$ cat ./testme1.sh
#!/bin/sh
set -e
this_command_should_not_be_found
echo "Should not still be running"

$ sh ./testme2.sh
./testme2.sh: /this_command_should_not_be_found: not found
$ cat ./testme2.sh
#!/bin/sh
set -e
/this_command_should_not_be_found
echo "Should not still be running"

>Fix:
>Release-Note:
>Audit-Trail:

From: David Laight <david@l8s.co.uk>
To: gnats-bugs@netbsd.org, netbsd-bugs@netbsd.org
Cc:  
Subject: bin/17514 bin/sh and -e
Date: Sat, 11 Jan 2003 12:45:05 +0000

 Some related 'features':

 - the man page (probably incorrectly) that -e only affects
   non-interactive shells.  The POSIX defn doesn't mention it under
   -e, but refers to a section which says that a non-interactive
   shell should have exited under many of the error cases even if -e
   wasn't set.

 - although 'false' will cause the shell to exit, (exit 3) doesn't,
   I suspect there are others.  (pdksh is also broken here, netbsd's
   shell from 1.5.2 does exit).

 - syntax errors (eg 'for ;') should also cause the shell to exit.

 I'll look into it.

 	David

 -- 
 David Laight: david@l8s.co.uk

From: David Laight <david@l8s.co.uk>
To: gnats-bugs@netbsd.org, netbsd-bugs@netbsd.org
Cc:  
Subject: Re: bin/17514 bin/sh and -e
Date: Sat, 11 Jan 2003 16:38:59 +0000

 On Sat, Jan 11, 2003 at 12:45:05PM +0000, David Laight wrote:
 > Some related 'features':
 > 
 > - the man page (probably incorrectly) that -e only affects
 >   non-interactive shells.  The POSIX defn doesn't mention it under
 >   -e, but refers to a section which says that a non-interactive
 >   shell should have exited under many of the error cases even if -e
 >   wasn't set.
 > 
 > - although 'false' will cause the shell to exit, (exit 3) doesn't,
 >   I suspect there are others.  (pdksh is also broken here, netbsd's
 >   shell from 1.5.2 does exit).
 > 
 > - syntax errors (eg 'for ;') should also cause the shell to exit.

 - a command error status picked up in 'fg'

 > I'll look into it.

 Fixing 'command not found' is relatively easy (just change the 'return'
 statement(s) in evalcommand to 'goto out').

 However the man page is wrong (ie disagrees with posix).

 posix says:
     -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 shall immediately exit.

 netbsd's man page says:
     -e	If not interactive, exit immediately if any untested command fails.
 	The exit status of a command is considered to be explicitly tested
 	if the command is used to control an if, elif, while, or until; or
 	if the command is the left hand operand of an ``&&'' or ``||''
 	operator.

 Note that posix says 'simple command' and does not exclude the right
 hand part of an && or || operator.

 This (probably) means that 'set -e; (exit 1);' should not cause the
 shell to exit - because (...) isn't a simple command (and the exit 1
 is in a differnt shell).

 However in 'false | true' and 'true | false' the 'false' is a simple
 command executed by the shell so maybe should cause the shell to exit.
 (the fact that pipelines preceeded by ! are specifically mentioned
 as not exiting does sort of imply that pipelines not preceeded by !
 should exit on error).

 pdksh exits on 'true | false', but not on 'false | true'.
 Detecting the latter is quite tricky (with the current code) as
 the status of the early parts of a pipeline is discarded.

 	David

 -- 
 David Laight: david@l8s.co.uk

From: David Laight <david@l8s.co.uk>
To: gnats-bugs@netbsd.org, netbsd-bugs@netbsd.org
Cc:  
Subject: Re: bin/17514 bin/sh and -e
Date: Sat, 11 Jan 2003 18:38:31 +0000

 > > Some related 'features':

 $ set -e; echo x$(exit 5)

 should also (probably) exit when the back-quoted command fails.
 (and so not echo anything before the shell exits).

 $ set -e; x=$(exit 5)

 does exit though (at least from my sources).

 	David

 -- 
 David Laight: david@l8s.co.uk
From: YAMAMOTO Takashi <yamt@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/17514 CVS commit: src/regress/bin/sh
Date: Thu, 31 Mar 2005 08:52:49 +0000 (UTC)

 Module Name:	src
 Committed By:	yamt
 Date:		Thu Mar 31 08:52:49 UTC 2005

 Modified Files:
 	src/regress/bin/sh: Makefile
 Added Files:
 	src/regress/bin/sh: set_e.sh

 Log Message:
 add a test for "set -e".  related to PR/17514.

 commented out in Makefile because i'm not sure
 what's a correct behaviour.


 To generate a diff of this commit:
 cvs rdiff -r1.7 -r1.8 src/regress/bin/sh/Makefile
 cvs rdiff -r0 -r1.1 src/regress/bin/sh/set_e.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/17514 CVS commit: src/tests/util/sh
Date: Sun, 25 May 2008 21:43:18 +0000 (UTC)

 Module Name:	src
 Committed By:	dholland
 Date:		Sun May 25 21:43:18 UTC 2008

 Modified Files:
 	src/tests/util/sh: t_set_e.sh

 Log Message:
 One more pair of cases; PR bin/17514 originally reported a difference in
 nonexistent programs on $PATH and nonexistent programs with an absolute
 pathname, so we ought to test both.

 If anyone creates a program called nonexistent-program-on-path and
 thereby breaks this test for themselves, they deserve it. ;-)

 Also prune a no-longer-used shell variable.


 To generate a diff of this commit:
 cvs rdiff -r1.4 -r1.5 src/tests/util/sh/t_set_e.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/17514 (/bin/sh `set -e' does not exit on command not found)
Date: Mon, 22 Feb 2016 00:19:12 +0700

 This is another (even older) PR related to sh's -e option, which is
 also fixed, so this one is another PR that ought be closed.

 kre

State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Sun, 21 Feb 2016 12:49:58 -0500
State-Changed-Why:
fixed a long time ago


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.