Skip to content

Instantly share code, notes, and snippets.

@jmound
Created November 19, 2021 17:27
Show Gist options
  • Save jmound/3163a200033569567e822df8b2949600 to your computer and use it in GitHub Desktop.
Save jmound/3163a200033569567e822df8b2949600 to your computer and use it in GitHub Desktop.
bash functions that exit on errors
Crafting bash functions that exit on errors:
function name {( set -e
do stuff...
)}
The (...) creates a subshell, and the "set -e" prefix causes an exit on any
nonzero exit codes of the included commands.
https://stackoverflow.com/a/58964551/90442
https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment