Exit codes and errors
8 minset -e and the six places it does not fire
A good default, and not a safety net.
set -e ends the script at the first command that fails without being checked. It is worth having. It is also full of holes, and knowing where they are is the difference between using it and relying on it.
It does not fire on a command whose status is being tested: the left of && or ||, the condition of an if, while or until, or a pipeline preceded by !.
Try this
It also does not see inside a pipeline: only the last stage's status counts, so a failing producer feeding a successful consumer looks like success.
set -o pipefail fixes that one, and set -u turns an unset variable into an error rather than an empty string. Together they are the reason set -euo pipefail is the usual first line.
Try this
set -euo pipefail is a good default. It is not a safety net: a script still has to say what it means.
Files
| Mode | Links | Size | Name |
|---|---|---|---|
| -rw-r--r-- | 1 | 94 | budget.md |
| -rw-r--r-- | 1 | 62 | summary.txt |