http://redsymbol.net/articles/unofficial-bash-strict-mode/
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
This causes bash to behave in a way that makes many classes of subtle bugs impossible.
set -e: exit script if any command has a non-zero exit status.
set -u: a reference to any variable you haven’t previously defined - with the exceptions of $* and $@ - is an error, and causes the program to immediately exit.
set -o pipefail: exit if any command in a pipeline fails
Caveat: with set -u, we need to be careful when checking if a variable is set.
The expression [ -z "$var" ], which returns true if the string $var is empty, will fail if var is not set.
Two safe alternatives:
set -u
name=${1:-}
if [[ -z "$name" ]]; then
echo "usage: $0 NAME"
exit 1
fi
set -u
if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fi