Bash Tips

http://redsymbol.net/articles/unofficial-bash-strict-mode/

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

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

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.

1 Like

My most important bash tip – use shfmt in your editor:

This will teach you best practices and highlight potential problems. Great stuff!