declare -A region_URLs
region_URLs[beijing]="https://1.com"
region_URLs[shanghai]="https://2.com"
region_URLs[Sydney]="https://3.com"
for site in "${!region_URLs[@]}"; do
echo $site -- ${region_URLs[$site]}
done
root@219:~# bash test.sh
shanghai -- https://2.com
Sydney -- https://3.com
beijing -- https://1.com
References: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/
本文展示了一个使用Bash脚本语言定义和遍历关联数组的例子。通过声明一个包含不同地区URL的关联数组,该脚本能够有效地遍历并打印出每个地区的名称及其对应的URL。

1065

被折叠的 条评论
为什么被折叠?



