↓ Skip to main content

Shell Scripting That Doesn't Suck

·59 words·1 min·
lrweck
Author
lrweck
Developer writing about tech, observations, and experiments.

The difference between a script that survives and one that eats data is usually three flags:

#!/usr/bin/env bash
set -euo pipefail

name="${1:-default}"
echo "Running with $name"
  • -e stops on error
  • -u catches unset variables
  • -o pipefail stops pipelines mid-stream

Quote every variable, use [[ ]] instead of [ ], and let ShellCheck be your reviewer. That’s the whole trick.

Related