In Bash, I can create a map (hash table) with this general construct
hput() { eval "$1""$2"='$3' } hget() { eval echo '${'"$1$2"'#hash}' }
and then use it like this:
hput capitals France Paris hput capitals Spain Madrid echo "$(hget capitals France)"
But what is the best way to iterate over entries on a map? For example, in Java, I would do:
for (Map.Entry<String, String> entry : capitals.entrySet()) { System.out.println("Country " + entry.getKey() + " capital " + entry.getValue()); }
Is there a general way to do something like this in Bash ?.
source share