Start every shell script with set -euo pipefail
By default a shell script keeps going after a failed command, treats an unset variable as an empty string, and reports a pipeline as successful if only its last command succeeded. Three lines fix all of that.
#!/usr/bin/env bash
set -euo pipefailYou will hit cases where you want a command to fail quietly. Write cmd || true there, on purpose, where a reader can see it.
shell