0

I am on a mac and I can not use declare -A. I've looked at a few questions already

1) Bash 4 associative arrays: error "declare: -A: invalid option"

2) declare -A bash does not work on mac os x

Both refer to as upgrading to bash version 4. So i've done brew install bash and even updated my etc/shells to update that to point to the bash that was installed by brew.

But the problem still exists.

Here is the outputs of my bash screen.

$ bash --version
GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.3.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ which bash
/usr/local/bin/bash

$ declare -A assoc_array=(["key1"]="value1" ["key2"]="value2")
-bash: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]

Thanks.

edster
  • 116
  • 2
  • 10
  • 1
    Try `echo $BASH_VERSION`. The copy of bash that you're running in your example may not be the one in /usr/local/bin. – Kenster Oct 26 '17 at 21:30
  • 1
    `bash --version` tells you which bash release is first in your PATH, **not** which one is currently running. – Charles Duffy Oct 26 '17 at 21:32
  • Specifically, you need to update your user's password database entry to point to the version of bash you want; updating `/etc/shells` is not sufficient. – Charles Duffy Oct 26 '17 at 21:33
  • Notably, the accepted answers on some of the questions you linked **already specify this**. See in particular the `chsh` command given in https://stackoverflow.com/a/44293632/14122 – Charles Duffy Oct 26 '17 at 21:37
  • 1
    Thanks alot @CharlesDuffy. That was it. `chsh` resolved the problem. I missed it when I read that other thread. Thanks! – edster Oct 27 '17 at 05:33
  • Hey @CharlesDuffy if you put what you said in the answers, then I could accept the answer as correct solution.. – edster Oct 27 '17 at 07:09
  • No need -- the question is already closed as a dupe. (As such, I *can't* add a new answer without first reopening it, but as I understand it we're agreed at this point that it *is* duplicative indeed). – Charles Duffy Oct 27 '17 at 17:14

0 Answers0