Bash pitfalls

With pipefail, cmd | grep -q x may fail even when x is found: grep exits early and the writer receives SIGPIPE.

Quote expansions. rm -rf $dir/ with an empty variable is a bad day.

set -e is ignored inside conditions.