-e flag (Was: shell &&, || constructs)

Chris Torek chris at mimsy.UUCP
Mon Oct 3 16:36:37 AEST 1988


>In article <13810 at mimsy.UUCP> I noted:
>>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 article <827 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>But this is according to the spec: exit *IMMEDIATELY* if a command fails.

Well, yes, it *does* match the specification (in a twisted sort of way).
It is merely useless.  (We wanted to *test* something!)

>However I agree the fix perhaps makes more sense. Maybe we need a new
>metacharacter (another one!) to indicate "ignore this command's exit
>status with regard to -e"; compare with make's - .

Just use (set +e; cmd).  (More on this in a moment.)

>Playing around with -e revealed some funny things:
>
>After a set -e, $- contains not only e but also s:
>
>$ echo $-
>
>$ set -e
>$ echo $-
>se

The `-s' option means `reading stdin'; it gets set automatically
*after* the shell sets up $-.  When you `set <anything>', sh updates
its list of currently set flags, and -s suddenly appears.  I regard
this as a minor bug, which I may fix later.

>After a set +e, an e flag in $- is not discarded; it seems to be treated
>as setting a positional parameter ... +e doesn't seem to work on my system.
>This happened with /bin/sh under Ultrix 2.0. Any comments?

I must have been living in an alternate universe for the last few years
:-) .  `set +opt' fails in the 4BSD `/bin/sh'es.  The odd thing is that
I remember using it, and remember it working. . . .

At any rate, `set +opt' is a SysV (SysIII?) addition.  It is present in
recent SunOS releases.  With any luck it will also be in 4.4BSD.
-- 
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



More information about the Comp.unix.questions mailing list