Strange issue with upgrading bash in Yosemite using Homebrew

4

I'm running OS X Yosemite. I need to use associative arrays in bash so I decided to use Homebrew to upgrade bash to 4.x. I performed the following steps:

  1. brew install bash
  2. I then added /usr/local/bin/bash to /etc/shells and rebooted for good measure.
  3. chsh -s /usr/local/bin/bash
  4. For good measure, I logged out and logged back in, though a simple Terminal restart would probably have sufficed.

When I open Terminal, things seem to be fine. If I say $SHELL --version I get GNU bash, version 4.3.30(1)-release (x86_64-apple-darwin14.0.0). Unfortunately, if I say echo $BASH_VERSION I get 3.2.53(1)-release. Also, I can't seem to use any of the advanced features of Bash 4.x, like associative arrays, e.g., declare -A foo says -bash: declare: -A: invalid option.

Interestingly, echo $0 says -bash.

What's going on here? How do I get my associative arrays?

Gregory Higley

Posted 2014-11-05T22:30:30.350

Reputation: 141

What says which bash? – Mirko Ebert – 2014-11-05T22:39:58.540

@tfb785 which bash gives /usr/local/bin/bash. – Gregory Higley – 2014-11-05T22:55:56.520

@tfb785 Also, /etc/paths has /usr/local/bin before /usr/bin, so that doesn't appear to be the issue. – Gregory Higley – 2014-11-05T22:56:28.743

Answers

4

I had a similar issue, and it turned out to be with the my #! path. Check to make sure you are not pointing it at:

#!/bin/bash

but at:

#!/usr/local/bin/bash

If you want to continue to use #!/bin/bash at the top, you might want instead do:

sudo ln -s /usr/local/bin/bash /bin/bash

Update:

If your $PATH has /url/local/bin before /bin and /usr/bin you can just do:

#!/usr/bin/env bash

for a solution that is less specific to the OS X/Homebrew setup.

bzvestey

Posted 2014-11-05T22:30:30.350

Reputation: 41