这应该将整个关联数组打印到控制台:
#!/bin/sh
declare -a array=([key1]='value1' [key2]='value2')
for key in ${!array[@]}; do
echo "Key = $key"
echo "Value = ${array[$key]}"
done
echo ${array[key1]}
echo ${array[key2]}
相反,它只打印最后一个变量:
[mles@sagnix etl-i_test]$ ./test.sh
Key = 0
Value = value2
value2
value2
我的错在哪里?
@htor:Bash 版本是 3.2.25(1)-release。