AKRABAT

Incredibly, macOS Mojave comes with Bash 3.22 by default still. Apparently this is due to licensing reasons, however Bash 4 has lots of lovely features including associative arrays that I’d like use. Hence, after reading the Internet for a bit, I’ve installed it on my Mac. This turned out to require just 3 commands:

$ brew install bash
$ sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
$ chsh -s /usr/local/bin/bash

Close the terminal and open a new one which now has Bash 4!

Bash4

Using Bash 4 in scripts

Any script that start with #!/bin/bash will continue to use Bash 3, so we use env in the same way as we do with PHP, Ruby or Python scripts and start our Bash script files with:

#!/usr/bin/env bash

This will now use Bash 4 when you run the script interactively.

Source: AKRABAT