BASH recommended initialisation sequence
November 2, 2015 Leave a comment
Writing scripts to automate repetitive tasks is very common, but it is not commonly known that bash defaults are not very robust.
In order to make bash better process error cases, it is necessary to set several options, one of the most notable being to complain about using variables without assigning them values.
The recommended code to do this is
#!/usr/bin/env bash if [[ ${DEBUG} != "" ]]; then set -x fi set -o errexit set -o pipefail set -o nounset IFS=$'\n\t'
The up-to-date version of the small snippet is available from Gist, together with some more explanations.