I need to check if an element in an associative array is set. What's the correct way to test it?
$ declare -A arr=([x]=y); var=* $ [[ -v arr["$var"] ]]; echo $? 0 $ [[ ${arr["$var"]} ]]; echo $? 1 The former seems wrong, the glob is expanded even if "$var" is quoted. The latter works but it doesn't distinguish between unset and empty. Is there a way to test it with ''[[ -v'' ? Also this one seems wrong, found by geirha: $ declare -A a=([x]=y); [[ -v a ]]; echo $? 1 $ declare -A a=(["0"]=y); [[ -v a ]]; echo $? 0 --- xoxo iza