2 ms·
I agree. You must fail fast. My best shell advice is to put these commands at the beginning of every script: set -e # stop scripts on errors set -u #
by neves 5y ago
I agree. You must fail fast.
My best shell advice is to put these commands at the beginning of every script:
set -e # stop scripts on errors
set -u # stop script if undefined var
set -o pipefail # stop script if there's a pipe failure
Use them to have a saner life.
- misnome 5y agoAnd you can compact them to set -euo pipefail
- l0b0 5y agoMy favourite set of pragmas: set -o errexit -o noclobber -o nounset -o pipefail shopt -s failglob inherit_errexit These are all easy to find in the Bash manual.
- creamytaco 5y agoFor most uses, I consider all of these unwanted at best and potential disasters at worst. If you use them, make sure you understand exactly what each of these do. If you just follow a dictum you found on HN blindly and just copy-paste them, you're in for a world of hurt. Example for set -e: https://mywiki.wooledge.org/BashFAQ/105 https://mywiki.wooledge.org/BashFAQ/105