Bash script: safer with “set -euxo pipefail”

An excellent blog post from Van Eyckt explains how starting a Bash script with:

#!/bin/bash
set -euxo pipefail

can help a lot in troubleshooting, making the script easier to write. With this single line the script will exit when a single command fails (-e), even when part of a pipe fails (-o).
The -u switch will prevent the use of unbound variables, while -x will print each command before execution, saving some echoes but messing the screen. Most of the times, I avoid the -x.