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

 
 

sr #108191: bash drops errexit option in sourced file

Submitter:  Robert Schiele <schiele>
Submitted:  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
* Mandatory Fields

Add a New Comment Rich Markup
   

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

Fixed in bash-4.3.

Chet Ramey <chet>
Group 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
#!/bin/bash
set -e

int()
{
    echo A: $-
    . source
    echo D: $-
}

echo Broken:
int && true

echo OK:
int
$ cat source
echo B: $-
false
echo C: $-
$ bash bug
Broken:
A: ehB
B: hB
C: hB
D: ehB
OK:
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:
   
   
Comment:
   

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)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-13 chet StatusNone Done

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code