What does `set -euo pipefail` do and why start scripts with it?
⚡
Quick Answer
It makes bash exit on errors (-e), on unset variables (-u), and propagate failures through pipelines (pipefail).
Detailed Answer
By default bash ignores most failures and keeps going, which hides bugs. -e exits on any command failure, -u treats using an unset variable as an error, and pipefail makes a pipeline fail if any stage fails (not just the last). It's the standard safety preamble for production scripts.
Code Example
#!/usr/bin/env bash set -euo pipefail
💡
Interview Tip
Reciting this preamble signals you write robust scripts.
bashsafetyset