我在Mac上,我无法使用declare -A
。
我已经看了几个问题
1)Bash 4 associative arrays: error "declare: -A: invalid option"
2)declare -A bash does not work on mac os x
两者都称为升级到bash版本4。
所以我已经完成了brew install bash
,甚至更新了我的etc/shells
以更新它以指向brew安装的bash。
但问题仍然存在。
这是我的bash屏幕的输出。
$ 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] ...]
感谢。