#!/usr/bin/env bash # # The Unofficial "Bash Strict Mode". # # -e Failed commands exit. # -u Unbound variables exit. # -o pipefail Do not hide piped-command failures. # IFS=$'\n\t' Newline/Tab separators are good for loops and names with spaces. # # Tips: # # 1. Avoid unset (unbound) variables. Use default values for: # - Positional parameters e.g. `${1:-}`. # - Potentially undefined variables e.g. `${ENVVAR:-}`. # - Intentionally empty/undefined variables e.g. `MAYBE_EMPTY=""`. # # 2. Failed Commands will stop the script. Avoid this by affixing ` || true`. # # 3. Strict Options can be toggled, if really required: # - Switch off: `set +opt`. Switch back on afterwards: `set -opt`. # - Toggle `-e` if the previous return value (`$?`) is needed. # - Toggle `-u` if sourcing a non-conforming script. # # 4. Exit Traps can perform try-catch-finally-like clean-up tasks. # # (These comments are all removed when vim loads this template.) # set -euo pipefail IFS=$'\n\t'