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"-estops on error-ucatches unset variables-o pipefailstops pipelines mid-stream
Quote every variable, use [[ ]] instead of [ ], and let ShellCheck be your reviewer. That’s the whole trick.