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: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: None
Privacy: PublicAssigned to: None
Open/Closed: OpenOperating System: GNU/Linux

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

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

 

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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by schiele (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to 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):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup