What would be the bash code after:
declare -A map
to do the following:
1) if a string does not yet exist in the map, create the entry for it and set its count (value) to 1
2) if the string already exists in the map, increment the count (value) by 1?
Am using post version 4.0 of Bash.
Based on @that other guy's answer, I tried:
#!/bin/bash
input=("a" "b" "a")
declare -a map
for i in ${input[@]}
do
let 'map[$i]++'
echo "map[$i]=${map[$i]}"
done
And when run it produces the following -- does NOT seem to work:
$ maptest
map[a]=1
map[b]=2
map[a]=3
declare -a mapdeclaresmapto be a list (i.e. indexed by integers). It's not the same asdeclare -A map, which does create an associative array.