Created
November 19, 2021 17:27
-
-
Save jmound/3163a200033569567e822df8b2949600 to your computer and use it in GitHub Desktop.
bash functions that exit on errors
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
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