Skip to content

Instantly share code, notes, and snippets.

@major0
Created May 16, 2014 21:16
Show Gist options
  • Save major0/159c0e25d0d24fced074 to your computer and use it in GitHub Desktop.
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.
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