[Top][All Lists]

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

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

From: Paul Smith
Subject: Re: Incompatibility with POSIX 2008--- /bin/sh -e?
Date: Wed, 10 Jun 2009 09:00:00 -0400

On Wed, 2009-06-10 at 00:17 -0400, David Boyce wrote:
> 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.

This may be a change in POSIX 2008; I'll have to go look at the text for
prior versions of the spec.

The man page for sh is a little more nuanced:

-e errexit       If not interactive, exit immediately if any
                 untested command fails.  The exit status of a com-
                 mand is considered to be explicitly tested if the
                 command is used to control an if, elif, while, or
                 until; or if the command is the left hand operand
                 of an ``&&'' or ``||'' operator.

according to this, only the left hand operand of the boolean operators
is considered "tested", which matches the behavior you're seeing.

Try running ''/bin/sh -ec "false && true; true"; echo $?'' and you
should get "0".  This is not bad because typically the last operation in
the boolean list is the thing you really care about (but not always).
Anyway you can always add "|| true" if you don't care.

I thought the shell was working as described in the spec I quoted but
now I realize I had a scripting error :-).

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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