BASH Pitfalls & How to avoid them

Disclaimer: I'm using fish shell on my laptop. It solves everything that's wrong with Bash, and is much more fun.

A few days ago I posted Test your terminal skills #1 to reddit. A few folks opened my eyes regarding the quality of my solutions, and directed me to two great resources.

Bash Pitfalls

Greg's Bash Guide - A guide tht aims to aid people interested in learning to work with BASH. It aspires to teach good practice techniques for using BASH, and writing simple scripts.

Also, There's a whole section for Bash Pitfalls, which is worth a read.

"Strict Mode"

Your bash scripts will be more robust, reliable and maintainable if you start them like this:

#!/usr/bin/env bash
set -euo pipefail

Why? Read Aaron Maxwell's excellent blog post: Use the Unofficial Bash Strict Mode.


ShellCheck finds bugs in your bash shell scripts.

You can grab it from here, or just paste your script to its website. It integrates well with syntastic & neomake, which makes it extremely powerful.

If you know of any other resources for common pitfalls, please comment below!