What does `set -euo pipefail` do in a bash script?
IntermediateConceptPackages, Shell & Text Tools
Answer
-e: exit on any command returning non-zero (with exceptions insideif,&&,||).-u: treat unset variables as errors.-o pipefail: a pipeline fails if any command in it fails, not just the last.
#!/usr/bin/env bash
set -euo pipefail
trap 'echo "failed at line $LINENO" >&2' ERR
Without pipefail, curl bad-url | tar xz reports success when curl fails, if tar exits 0.
More on Packages, Shell & Text Tools
Compare apt and dnf package management.BeginnerWhat is the difference between `apt upgrade` and `apt full-upgrade`?IntermediateHow do you find which package provides a file or command?BeginnerHow do you pin or hold a package version?IntermediateHow are repositories and their GPG keys configured?AdvancedWhat is the difference between a login shell and an interactive non-login shell?Intermediate