Bash Tips

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.

1 Like

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

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