Use Bash Strict Mode (Unless You Love Debugging)

Let’s start with the punchline. Your bash scripts will be more robust, reliable and maintainable if you start them like this:

set -euo pipefail

I call this the unofficial bash strict mode. This causes bash to behave in a way that makes many classes of subtle bugs impossible. You’ll spend much less time debugging, and also avoid having unexpected complications in production.