Bash Strict Mode

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:

1#!/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.

There is a short-term downside: these settings make certain common bash idioms harder to work with. Most have simple workarounds, detailed below: jump to Issues & Solutions. But first, let’s look at what these obscure lines actually do.

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

This thread was posted by one of our members via one of our news source trackers.

Corresponding tweet for this thread:

https://twitter.com/dev_talk/status/1350188294278160385

Share link for this tweet.