What does set -euo pipefail do in bash scripts?
Answer
set -euo pipefail is the recommended safety header for production bash scripts. -e (errexit) causes the script to exit immediately when any command exits with a non-zero status — preventing silent failures from cascading. -u (nounset) treats references to undefined variables as errors, catching typos in variable names before they cause data loss (rm -rf $DIOR/ vs rm -rf $DIR/). -o pipefail makes a pipeline fail if any command in it fails, not just the last one — without this, cmd1 | cmd2 succeeds even if cmd1 fails because only cmd2's exit code is checked. Add set -euo pipefail as the second line of every non-trivial bash script.
Previous
What is the difference between a symbolic link and a hard link?
Next
What is a heredoc (<<EOF) in bash and when is it used?