Get the latest tech news

Bash Strict Mode (2014)


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: - #!/bin/bash - set -euo pipefail - IFS=$'\n\t' I call this the unofficial bash strict mode.

The linked article explains this important pattern in detail, and I highly recommend you master the technique - having it in your toolbox significantly makes your scripts more robust and reliable. The whole point of strict mode is to convert many kinds of hidden, intermittent, or subtle bugs into immediate, glaringly obvious errors. It turns out the-e option has a special exception in short-circuiting expressions like this: if COND evaluates as false, COMMAND will not run, and flow of execution will proceed to the next line.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Bash Strict Mode

Bash Strict Mode