shell &&, || constructs
Doug Gwyn
gwyn at smoke.ARPA
Mon Oct 3 17:14:45 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.)
The correct behavior is for "failure || failure" to count as an error
with respect to "set -e", and the other combinations of operands to ||
to not count as an error. BRL's SVR2-based shell works this way; I
seem to recall that there was a bug in the eflag handling that had to
be fixed, although it might not have involved || (I don't remember).
Obviously you don't want to make your shell scripts depend on this if
you're concerned about portability.
More information about the Comp.unix.questions
mailing list