Skip to content

Instantly share code, notes, and snippets.

@n0mn0m
Created April 18, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0mn0m/d6d2c9f4a159e3ab80bb956836a4911f to your computer and use it in GitHub Desktop.
Save n0mn0m/d6d2c9f4a159e3ab80bb956836a4911f to your computer and use it in GitHub Desktop.
shell remember
#!/usr/bin/env bash
set -euo pipefail
I don't normally use bash, but found this to be interesting:
The first statement is a Mac, GNU/Linux, and BSD portable way of finding the location of the bash interpreter. The second statement combines
“set -e” which ensures that your script stops on first command failure. By default, when a command fails, BASH executes the next command. Looking at the logs, you might feel that the script executed successfully while some commands might have failed. Caveat: Be careful about applying it to existing scripts.
“set -u” which ensures that your script exits on the first unset variable encountered. Otherwise, bash replaces the unset variables with empty default values.
“set -o pipefail” which ensures that if any command in a set of piped commands failed, the overall exit status is the status of the failed command. Otherwise, the exit status is the status of the last command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment