/bin/sh -e behaviour
Chris Torek
chris at mimsy.UUCP
Sat Oct 8 12:40:28 AEST 1988
>In article <639 at eiger.iis.UUCP> prl at iis.UUCP (Peter Lamb) writes:
>>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!
In article <831 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>Of course, but you must take two other things into account:
>1) the conditional is not the exit status of a (1) command, but of a
>command list. I can even write something down like:
>
>if
><shell script here>
>then
><other stuff here>
>fi
>
>and put a whole shell script into the conditional clause (not that this
>is common practice). Now do you want -e to be turned off for the whole
>clause (see also beneath) ??
Yes. If you meant for -e to be in effect for most of the test part,
you can write either of the following:
<most of script>
if <last of script>
then
<other stuff>
fi
or, more generally,
if (set -e; <most of script>); last of script
then
<other stuff>
fi
since in SysV and in with my changes the suppression of error-exit is
actually implemented by temporarily turning off `-e'. Curiously, this
turns up a minor bug in the SysV sh in SunOS:
$ set -e; echo $-
se
$ if set -; echo $-; then echo ok; fi
s
ok
$ echo $-; set -; echo $-
s
se
$
The code that fiddles with the internal `-e' flag does not also fiddle
with $-, but `set -' resets $- per the current flags, so $- does not
always reflect the actual settings.
>2) -e is used when successfull execution of the commands in a script is
>a must; take for instance the 'Make' example. Why would the commands in
>the commandlist of a conditional clause suddenly be all that different?
Well, it is *conditional*....
>A minimal change to the meaning of -e ...:
>The last command of the conditional clause's command list should not
>cause an exit if it fails and -e is set.
Alas, this is hard; temporarily suppressing -e is much easier. Guess
which wins :-) .
--
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