Explain `set -euo pipefail` line by line, and add the `-E` flag.
BeginnerConceptFunctions, exit codes, strict mode and traps
Answer
set -Eeuo pipefail
-e: exit when an unchecked command fails.-u: treat expansion of an unset variable as an error (DB_HOST: unbound variable), catching typos.-o pipefail: a pipeline's status is the last non-zero status of any stage, socurl ... | jq ...fails ifcurlfails.-E: theERRtrap is inherited by functions, command substitutions and subshells.
Write defaults for optional variables with ${VAR:-} so -u does not trip on legitimately unset values.
More on Functions, exit codes, strict mode and traps
How do you define a function, pass arguments and return a value?BeginnerWhat does `local` do, and what is dynamic scoping?AdvancedWhy is `local out=$(cmd)` a problem under `set -e`?AdvancedWhat are the conventional exit codes, and what do 126, 127, 130, 137 and 143 mean?BeginnerWhat does `set -e` do, and where does it NOT cause an exit?AdvancedWhy can `((count++))` kill a script under `set -e`?Intermediate