Last active
April 2, 2020 18:53
-
-
Save cobbr2/d605ab39fcf93edde4e79b5d9be056d6 to your computer and use it in GitHub Desktop.
Bash `-e` does not propagate to called scripts, but does to functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source ./bash_fn | |
set -e | |
./bash_script | |
bash_fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bash_fn() { | |
echo "function: Before failing command" | |
false | |
echo "function: After failing command" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "script: Before failing command" | |
false | |
echo "script: After failing command" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./bash_caller | |
script: Before failing command | |
script: After failing command | |
function: Before failing command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you run a shell script, it's in a child process. Bash functions run in the same process as their caller.