#! /usr/bin/bash declare -A family family=([father]="Homer" [mother]="Marge" [son]="Bart" [daughter]="Lisa" [baby]="Maggie") echo "Iterating through associative array using while loop:" while IFS= read -r key && IFS= read -r value <&3; do echo "Key: $key, Value: $value" done < <(printf '%s\n' "${!family[@]}") 3< <(printf '%s\n' "${family[@]}")