在 bash 中覆盖 hashmap 的值
我在 bash 脚本中声明了一个哈希图,其值取决于我的环境变量。
export test_ENVIRONMENT=1
if [ -z "$test_ENVIRONMENT" ]; then
echo "Environment variable test_ENVIRONMENT is not set."
exit 1
fi
echo $test_ENVIRONMENT;
hashmap["1"]="1"
hashmap["2"]="2"
MySql="select distinct url as urls from t where
REGION=${hashmap["$test_ENVIRONMENT"]}
and visitday >= TO_DATE(SYSDATE-5,'DD-MON-YYYY')
AND visitday <= TO_DATE(SYSDATE, 'DD-MON-YYYY')
order by urls ;"
echo $mySql
exit;
我使用不同的 test_environment 值运行脚本三次
export test_environment=1
export test_environment=2
export test_environment=1
在过去两次中,我的区域值设置为 2 而不是 1。
即,在为 test_envoironment 设置不同的值时,第二个值始终会覆盖初始值。我在这里错过了什么吗?
I have declared a hashmap in my bash script whose value is dependent on my environment variable.
export test_ENVIRONMENT=1
if [ -z "$test_ENVIRONMENT" ]; then
echo "Environment variable test_ENVIRONMENT is not set."
exit 1
fi
echo $test_ENVIRONMENT;
hashmap["1"]="1"
hashmap["2"]="2"
MySql="select distinct url as urls from t where
REGION=${hashmap["$test_ENVIRONMENT"]}
and visitday >= TO_DATE(SYSDATE-5,'DD-MON-YYYY')
AND visitday <= TO_DATE(SYSDATE, 'DD-MON-YYYY')
order by urls ;"
echo $mySql
exit;
I am running the script three times with different values of test_environment
export test_environment=1
export test_environment=2
export test_environment=1
In last two times, my region value is set to 2 rather than 1.
i.e On setting different values for test_envoironment, the second value is always overwriting the initial value. Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该检查您的
bash --version
。bash 4.0 之后支持
关联数组
。You should check your
bash --version
.Associative array
is supported after bash 4.0.