我已经创建了关联数组,但是当我尝试在for循环中打印它时,我并没有获得所有值。我试图查找一个示例,但是没有示例可以打印二维关联数组。这是我的脚本:
#!/bin/bash
declare -A links
links["A",0]="linkA1"
links["A",1]="linkA2"
links["B",0]="linkB1"
links["B",1]="linkB2"
links["C",0]="linkC1"
links["C",1]="linkC2"
links["C",2]="linkC2"
#echo "${links["A",0]}"
#echo "${links["A",1]}"
#echo "${links["B",0]}"
for i in ${#links[@]} ; do
echo "key: $i"
j=0
while [ "${j}" -le 2 ]; do
echo "value: ${links["${i}","${j}"]}"
j=$(( $j + 1 ))
done
done