Created
December 18, 2013 18:41
-
-
Save pmorie/8027518 to your computer and use it in GitHub Desktop.
bash -eu, explained
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
# Source: http://fvue.nl/wiki/Bash:_Error_handling | |
# | |
#!/bin/bash -eu | |
# -e: Exit immediately if a command exits with a non-zero status. | |
# -u: Treat unset variables as an error when substituting. | |
(false) # Caveat 1: If an error occurs in a subshell, it isn't detected | |
(false) || false # Solution: If you want to exit, you have to detect the error yourself | |
(false; true) || false # Caveat 2: The return status of the ';' separated list is `true' | |
(false && true) || false # Solution: If you want to control the last command executed, use `&&' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment