make-alpha
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incompatibility with POSIX 2008--- /bin/sh -e?


From: David Boyce
Subject: Re: Incompatibility with POSIX 2008--- /bin/sh -e?
Date: Wed, 10 Jun 2009 00:17:03 -0400

On Tue, Jun 9, 2009 at 11:42 PM, Paul Smith<address@hidden> wrote:
> I think you really meant something like this:
>
>        test -f foo && rm -f foo ; echo hi
>
> thinking that with -e we would exit immediately if the test failed and
> the "echo hi" would not be invoked.  But that's not how -e works; from
> the POSIX spec:
>
>        -e
>                When this option is on, if a simple command fails for
>                any of the reasons listed in Consequences of Shell
>                Errors or returns an exit status value >0, and is not
>                part of the compound list following a while, until, or
>                if keyword, and is not a part of an AND or OR list, and
>                is not a pipeline preceded by the ! reserved word, then
>                the shell shall immediately exit.
>
> Note the second half of this sentence.

That may be what POSIX says but this is what shells do:

% sh -c "true && false ; true"; echo $?
0
% sh -ec "true && false ; true"; echo $?
1

I tested this just now with bash, /bin/sh, and /usr/xpg4/bin/sh on
Solaris 10. The latter should be strictly POSIX conformant.

>>     some-command
>>     if [ $? -ne 0 ]; then
>>         (work around the problem)
>>     fi
>>
>> will not work as designed.
>
> This is definitely true, although this common form works fine:
>
>        if ! some-command; then
>                (work around the problem)
>        fi

Granted there are idioms which *do* work with -e; the important point
is that there exist common ones which don't.

-David Boyce




reply via email to

[Prev in Thread] Current Thread [Next in Thread]