Skip to content

Instantly share code, notes, and snippets.

@pmorie
Created December 18, 2013 18:41
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmorie/8027518 to your computer and use it in GitHub Desktop.
Save pmorie/8027518 to your computer and use it in GitHub Desktop.
bash -eu, explained
# 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