Skip to content

.tip

· one of the small things

Start every shell script with set -euo pipefail

By default a shell script carries on after a failed command, treats an unset variable as an empty string, and calls a pipeline successful as long as its last command succeeded. Three lines fix all of that.

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

You'll hit cases where you want a command to fail quietly. Write cmd || true there, deliberately, where a reader can see it.

shell