bug-bash
[Top][All Lists]
Advanced

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

Re: bash drops errexit option in sourced file


From: Chet Ramey
Subject: Re: bash drops errexit option in sourced file
Date: Mon, 03 Dec 2012 11:29:56 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20121010 Thunderbird/16.0.1

On 12/3/12 11:07 AM, Chet Ramey wrote:
> On 12/3/12 10:50 AM, Robert Schiele wrote:
>> On Mon, Dec 3, 2012 at 4:25 PM, Chet Ramey <chet.ramey@case.edu> wrote:
>>> Since the `source' command is called in a context where all commands within
>>> it should have the `errexit' flag disabled, bash chooses to satisfy this
>>> requirement by turning off the flag that (internally) represents errexit.
>>> Under most circumstances, however, that state is externally visible as the
>>> value of the -e option.
>>>
>>> Note that the behavior of suppressing the effect of the errexit option is
>>> correct.  The value of the -e option in $- should be unaffected, though.
>>
>> Ah, now I start to understand how this is supposed to work. I also
>> realized that it is not possible within the function to turn on the
>> flag again with another internal set -e. Is that also part of the
>> design, meaning there is no way to have an effective set -e within a
>> function in case it was called in that context?
> 
> Correct.  When called in a context where errexit is ignored, attempts to
> turn errexit on are ineffective.

I should note that there's a potential problem with the effect of turning
on set -e in a sourced file even when it's called from a function in a
context where errexit is ignored.

Bash allows set -e to be enabled within the sourced file and have its
usual short-circuiting effect.  That's probably not quite the right thing
to do, so I will have to take a look at it.

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/



reply via email to

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