Why don't Bash associative arrays maintain index order?
问题 I'm creating associative arrays to process in a for loop but i'm getting some strange results in index order. Please take a look at this example script: #!/bin/bash declare -A test1=( [d]=1w45 [e]=2dfg [m]=3df [o]=4df ) declare -A test2=( [d1]=1w45 [e2]=2dfg [m3]=3df [o4]=4df ) declare -A test3=( [1d]=1w45 [2e]=2dfg [3m]=3df [4o]=4df ) echo ${!test1[@]} echo ${!test2[@]} echo ${!test3[@]} The output will be $ ./test d e m o o4 m3 e2 d1 3m 4o 1d 2e Why is the order of items changing? And how