Using:
set -o nounset
Having an indexed array like:
myArray=( "red" "black" "blue" )
>
This is the easiest way I found for scripts.
is the string you want to find, ASSOC_ARRAY the name of the variable holding your associative array.
Dependign on what you want to achieve:
key exists:
if grep -qe "" <(echo "${!ASSOC_ARRAY[@]}"); then echo key is present; fi
key exists not:
if ! grep -qe "" <(echo "${!ASSOC_ARRAY[@]}"); then echo key not present; fi
value exists:
if grep -qe "" <(echo "${ASSOC_ARRAY[@]}"); then echo value is present; fi
value exists not:
if ! grep -qe "" <(echo "${ASSOC_ARRAY[@]}"); then echo value not present; fi