【发布时间】:2017-04-06 20:46:29
【问题描述】:
我已经按照每个 bash 字典示例进行了操作,但没有一个会起作用。我现在有
_配置:
#!/bin/bash
instance_map["dev"]=project-dev
instance_map+=( ["stage"]="project-staging" )
declare -A animals=( ["moo"]="cow" ["woof"]="dog")
test.sh:
#!/bin/bash
source _CONFIG
echo ${instance_map["dev"]}
echo ${instance_map["stage"]}
echo "${animals[moo]}"
for sound in "${!animals[@]}"; do echo "$sound - ${animals[$sound]}"; done
由于某种原因,在遵循每个示例之后,我得到了
$ ./test.sh dev
_CONFIG: line 9: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
project-devproject-staging
project-devproject-staging
dog
0 - dog
$ bash --version
GNU bash, version 4.4.0(1)-release (x86_64-apple-darwin15.6.0)
如何在 Bash 中将用户输入“dev”映射到“myprojectname”?
【问题讨论】:
-
您已经安装了第二个 bash。但脚本使用默认的
/bin/bash。 (舍邦)。默认值为 3.2(不知道-A)。当您键入bash --version时,将搜索 PATH 并执行您准备的 bash ...将您的 shebang 更改为#!/usr/bin/env bash或更改路径,例如#!/usr/local/bin/bash。 -
你可以接受我的回答,如果你愿意,我会接受
-
自己接受吧。您可以接受自己的答案:) :)
标签: bash macos dictionary