Shell Scripting / Bash Tricks
Stop hunting for hidden command errors in your scripts
🧩 The Challenge
You write a twenty-line script, run it, and it silently fails halfway through because one command choked. Then you’re left guessing which line died while the rest of the logic kept blindly executing.
💡 The Fix
Throw a few built-in shell options at the top of your script to make it die immediately when things go sideways. It saves you from debugging absolute garbage state later.
set -euo pipefail
⚙️ Why It Works
Setting these flags tells bash to exit on any error, treat unset variables as fatal, and ensure pipes fail if any command in the chain returns a non-zero exit code. It’s the difference between a clean exit and a script that burns your entire configuration directory.
🚀 Pro-Tip: Use set -x if you need to watch the script vomit every single command it executes to the terminal while you troubleshoot.
Linux Tips & Tricks | © ngelinux.com | 7/13/2026
