I tried to do the opposite of if in shell to only do something if a value in a hash doesn't exist. I've learned to create a hash in bash from here:Associative arrays in Shell scripts
declare -A myhash
I declared a simple hash:
myhash[$key]="1"
and
[ ${myhash[$key]+abc} ]
to see if myhash[$key] exist or not from here: Easiest way to check for an index or a key in an array?
I also learned to add ! in front of an expression to do the opposite in if clause from here:How to make "if not true condition"?
But the following expression
if ! [ ${myhash[$key]+abc} ]; then
echo $key
fi
doesn't work and no information is printed. There is no error message.
I tried this:
[ ${myhash[$key]+abc} ] && echo $key
And got the error message:
abc: command not found
Can anyone tell me how to make it work?