She Bang Bin Bash

She Bang Bin Bash

Apparently, Apple is being a big baby and not installing a modern version of bash on macOs any longer.

macOs is currently shipping with bash version 3. This is fine in most cases but what if you want to use some of the modern conveniences that come with bash >= 4? (like associative arrays).

we can do that by installing the latest version (version 5 at the time of this writing) using homebrew.

brew install bash
brew link bash

The Catch!

we dont want to use the old version 3 binary that is still living on the machine so we can no longer use #!/bin/bash at the top of our bash scripts.

The Solution

We have to get in the habit of using the users specified version of bash

#!/usr/bin/env bash

Additionally, I have been including a check for bash >= 4 in my scripts that use associative arrays like so:

# Ensure bash version is greater than or equal to 4, so we can use associtative arrays
if [ "${BASH_VERSINFO:-0}" -le 4 ]
then  
	echo "You need bash >= 4"
    exit 0
fi