I am currently trying to loop through an associative array. This array contains values with the same key. However, when i tried to loop through it, I only get one set of results. How can I loop through all the values containing the same key?
#!/bin/bash/
declare -A details=( [dog]="golden retriver" [cat]="bengal" [bird]="eagle" [dog]="bulldog" [cat]="sphynx" [bird]="parakeet" )
for k in "${!details[@]}"
do
echo $k --- ${details[$k]}
done
Result
cat --- sphynx
dog --- bulldog
bird --- parakeet
Aucun commentaire:
Enregistrer un commentaire