Subject: Re: bin/17514 bin/sh and -e
To: None <gnats-bugs@netbsd.org, netbsd-bugs@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 01/11/2003 16:38:59
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