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?

4

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .