helpThe GNU Bourne-Again SHell - Support: sr #108191, bash drops errexit option in...


sr #108191: bash drops errexit option in sourced file

Submitted by:  Robert Schiele <schiele>
Submitted on:  Thu 29 Nov 2012 10:46:48 AM UTC  
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Fri 13 Nov 2015 02:44:46 AM UTC, comment #1:

Fixed in bash-4.3.

Chet Ramey <chet>
Project Administrator
Thu 29 Nov 2012 10:46:48 AM UTC, original submission:

While normally sourced files have identical options set like the invoking environment this is not true if the sourcing is done from within a function foo that was called with something like:

foo && true

The following example demonstrates this:

$ cat bug
set -e

echo A: $-
. source
echo D: $-

echo Broken:
int && true

echo OK:
$ cat source
echo B: $-
echo C: $-
$ bash bug
A: ehB
B: hB
C: hB
D: ehB
A: ehB
B: ehB

This error showed up in bash 4.0 first and was not present in 3.2 or older.

As you can see in the invocation "int && true" the flag is still set inside the function but magically disappears once the file is sourced, while in the second incocation "int" everything behaves as expected. Apparently something gets broken when the exit on error is temporarily disabled for the chained command "int && true" because while it gets properly restored within the function itself it disappears again when sourcing the other file.

Robert Schiele <schiele>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by schiele (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    Fri 13 Nov 2015 02:44:46 AM UTC chet StatusNone => Done

    Back to the top

    Powered by Savane 3.3