shell &&, || constructs (really /bin/sh -e behaviour)

Peter Lamb prl at iis.UUCP
Tue Oct 4 16:14:31 AEST 1988


In article <13810 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>Regarding `set -e': again, beware!  Old versions of /bin/sh will
>exit if the test portion of an `if', `while', or `until' returns
>a nonzero status, if `-e' is set.  (These are fixed in 4.3BSD-tahoe.)
>In addition, `command1 || command2' will exit if command1 fails.
>(It will also exit if command2 fails, but that seems sensible.
>I believe SysV's /bin/sh does *not* exit if command2 fails.  If
>this is considered correct behaviour, let me know, because I just
>`fixed' this to work the way I think seems sensible.)
>
>In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
>Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris

And some not-so-old /bin/sh's. This is one of my pet peeves with
Ultrix. Up to and including Ultrix 2.2 DEC's /bin/sh does just this,
which makes makefiles using conditionals difficult to do right.
DEC's /bin/sh5 (SysV shell) works correctly in this respect, but...
because DEC added the { command ; command } syntax to their shell,
and then put this in just about every critical shell script on the system,
you can't make the SysV shell /bin/sh (or rather you can, but you
won't be able to boot multi-user nor load DEC layered products :-) .

And just to support Chris' case that sh -e should not exit if the
command in a conditional returns non-zero status;

if you have a conditional, it is usually because you *EXPECT* the
thing to fail sometimes, otherwise you wouldn't have bothered!


-- 
Peter Lamb
uucp:  seismo!mcvax!ethz!prl	eunet: prl at ethz.uucp	Tel:   +411 256 5241
Institute for Integrated Systems
ETH-Zentrum, 8092 Zurich



More information about the Comp.unix.questions mailing list