In Example_1, when i have declared city to be an array with declare -A, why is Bangalore output first when the array is printed in the for loop?
Bangalore
Remote
Kolkata
Ahmedabad
Hyderabad
Pune
Mumbai
Delhi
Chennai
in Example_2, I believe its sorted in numerical order
example_1
$ cat novice_3.sh
#!/bin/bash/
declare -A city=( ["0"]="Mumbai" ["8"]="Delhi" ["16"]="Kolkata"
["26"]="Bangalore" ["32"]="Chennai" ["40"]="Pune"
["50"]="Hyderabad" ["56"]="Ahmedabad" ["17"]="Remote" )
for i in ${!city[@]};do
echo "${city[$i]}"
done
$ sh novice_3.sh
Bangalore
Remote
Kolkata
Ahmedabad
Hyderabad
Pune
Mumbai
Delhi
Chennai
example_2
$ cat novice_3.sh
#!/bin/bash/
declare city=( ["0"]="Mumbai" ["8"]="Delhi" ["16"]="Kolkata"
["26"]="Bangalore" ["32"]="Chennai" ["40"]="Pune"
["50"]="Hyderabad" ["56"]="Ahmedabad" ["17"]="Remote" )
for i in ${!city[@]};do
echo "${city[$i]}"
done
$ sh novice_3.sh
Mumbai
Delhi
Kolkata
Remote
Bangalore
Chennai
Pune
Hyderabad
Ahmedabad