set -e
The shell option that makes a script exit as soon as a command fails, instead of carrying on.
In more detail
It ignores failures that are already handled: commands tested by if, while or until, anything on the left of || or &&, and non-final pipeline stages unless pipefail is on. local x=$(cmd) also hides the failure, because local itself succeeds. Treat it as a seatbelt and still check the statuses you care about.
Example
set -euo pipefailRelated terms
- set -euo pipefail — The line many bash scripts put just under the shebang to turn on set -e, set -u and pipefail together.
- set -u — The shell option that makes using an unset variable an error that stops the script, instead of silently expanding to nothing.
- pipefail — The bash option that makes a pipeline fail if any stage fails, instead of reporting only the last stage's status.
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- shell script — A text file of shell commands that runs them in order, top to bottom, as if you had typed them one by one.
Taught in
- set -e, set -u And pipefail: Promises And Traps — Bash Scripting & Command Line Automation
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation
- Style That Prevents Bugs — Bash Scripting & Command Line Automation
- What Is a Pipeline? — Continuous Integration & Continuous Delivery Pipelines
- Triggers and the Event Model — Continuous Integration & Continuous Delivery Pipelines
- Passing Data Between Jobs: Artifacts — Continuous Integration & Continuous Delivery Pipelines
- Speeding Up Builds: Caching Dependencies — Continuous Integration & Continuous Delivery Pipelines
- Securing Pipelines: Secrets Management — Continuous Integration & Continuous Delivery Pipelines
- Environment Protection and Manual Approvals — Continuous Integration & Continuous Delivery Pipelines
- Repository Layout for Environments — Continuous Integration & Continuous Delivery Pipelines
- Rolling Back Blue-Green — Continuous Integration & Continuous Delivery Pipelines