How to update bash on Mac OS X Yosemite

Your problem is in your first line. You have this:

#!/bin/bash

which explicitly states that the shell script should be ran with the old /bin/bash. What you really want, is this:

#!/usr/local/bin/bash

to use the new bash from /usr/local/bin.


Install new bash:

brew install bash

Make this the default shell:

chsh -s /usr/local/bin/bash

Set the environment in a script:

#!/usr/bin/env bash

Using env will look for Bash in your $PATH and use the first one it encounters. You can see which bash it will use by typing which bash. If it's seeing /bin/bash first, you will need to set your $PATH in ~/.bashrc and /.bash_profile.


As pjv pointed out, you really should use

#!/usr/bin/env bash

in your scripts everywhere to be portable. E.g. if you try to run your script with

#!/usr/local/bin/bash

it will fail on most linux systems.