NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/37493: /bin/sh exits if shift fails, but shouldn't
The following reply was made to PR bin/37493; it has been noted by GNATS.
From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: bin/37493: /bin/sh exits if shift fails, but shouldn't
Date: Sun, 25 May 2008 07:01:31 +0000
On Thu, Dec 06, 2007 at 09:55:01PM +0000, rillig%NetBSD.org@localhost wrote:
> When "shift" is used in "set -e" mode, the shell exits if the "shift"
> occurs in a conditional statement. This is unexpected and not covered by
> the documentation.
>
>
> >How-To-Repeat:
> $ sh -c 'set -ex; shift || echo failed.'
> + shift
> shift: can't shift that many
So, the issue is that on line 1039 of eval.c there's a test that
re-raises the exception (EXERROR, aka "error") if the command was a
special builtin. This gets caught in main() and results in _exit(2),
whether or not -e is used; a bad shift is immediately and
unconditionally fatal.
Commenting that test out yields the expected behavior.
However, commenting it out clearly is the wrong thing. It would make
things like sh -c 'set -Z || echo failed' not bail out, which would be
wrong, or at least inconsistent with ksh/bash/zsh. (-Z is an illegal
option.)
I'm thinking that shift should be changed to an ordinary builtin
instead of a special builtin. But I'm not sure what other implications
this might have. Would someone who understands the finer points of sh
like to comment?
Also... ksh exhibits the same behavior. So, apparently, does the
original Bourne shell. bash and zsh do not. Which makes it unclear if
it's really a bug or not, too...
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index