[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: |
Chet Ramey |
Subject: |
Re: set -e in (subshells) does not work independently of outer context |
Date: |
Tue, 24 Jan 2012 12:03:38 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
On 1/24/12 4:53 AM, Jim Avera wrote:
> Bash Version: 4.2
> Patch Level: 10
> Release Status: release
>
> 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.
That sentence is cribbed from the Posix description, and means that if
the -e setting is active in a subshell, it affects whether or not that
subshell exits on command failure, but the outer shell may or may not
exit depending on its context.
The Posix example is
set -e; (false; echo one) | cat; echo two
where the subshell inherits set -e because it's not in a place where it's
ignored, and exits due to the `false' failing, but does not affect the
exit status of the pipeline. The failure of the subshell does not imply
the failure of the pipeline.
As Eric said, the other parts of the Posix description make it clear that
the `ignoring set -e' status is inherited by subshells.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/