Created
May 16, 2014 21:16
-
-
Save major0/159c0e25d0d24fced074 to your computer and use it in GitHub Desktop.
Bash fails to call exit_handler() if an error happens in the function called within a subshell.
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
set -e | |
exit_handler() { echo "exit code: $?"; } | |
false() { !:; } | |
main() | |
{( | |
trap exit_handler 0 | |
"$@" >> /dev/null 2>&1 | |
)} | |
main "$@" | |
echo "after main" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment