bug-bash
[Top][All Lists]
Advanced

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

Re: set -e in (subshells) does not work independently of outer context


From: Eric Blake
Subject: Re: set -e in (subshells) does not work independently of outer context
Date: Tue, 24 Jan 2012 09:41:36 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0

On 01/24/2012 02:53 AM, Jim Avera wrote:
> Description:
> set -e in (subshells) should be independent of surrounding context.
> The man page says "[set -e] applies to the shell environment and
> each subshell environment separately",
> but actually set -e is prevented from working in a (subshell) if it is
> disabled in the
> surrounding context.
> 
> Repeat-By:
>     set +e
>     (
>       set -e
>       cat /non/existent/path
>       echo "Did not abort.  Isn't this a bug?"
>     ) || true

Alas, POSIX requires this behavior.
http://austingroupbugs.net/view.php?id=52


>     In summary, shouldn't set -e in (subshell code) operate independently
>     of the surrounding context?

No.  The POSIX description is clear that surrounding context affects
whether set -e is ignored in a subshell.

  2) The -e setting shall be ignored when executing the compound
          list following the while, until, if, or elif reserved word,
          a pipeline beginning with the ! reserved word, or any
          command of an AND-OR list other than the last.

My personal advice - don't ever expect 'set -e' to work; there are just
too many pitfalls and buggy shell implementations with differing
interpretations to ever expect it to be useful, even if there is a
standardized documentation for how it should behave, and even if bash
has (finally) caught up to the standards.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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