Skip to content

Linux

Bash Strict Mode Header Generator

Pick set -e, set -u, pipefail, safe IFS, and an error trap - a commented script header explaining what each one actually catches.

#!/usr/bin/env bash

# Exit immediately if any command fails, instead of continuing with a partially-completed script.
set -e

# Treat unset variables as an error - catches typos in variable names instead of silently expanding to empty.
set -u

# A pipeline fails if ANY command in it fails, not just the last one - without this, `false | true` exits 0.
set -o pipefail