In Bash, what is the simplest way to test if an array contains a certain value?
Using parameter expansion:
${parameter:+word} If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.
declare -A myarray
myarray[hello]="world"
for i in hello goodbye 123
do
if [ ${myarray[$i]:+_} ]
then
echo ${!myarray[$i]} ${myarray[$i]}
else
printf "there is no %s\n" $i
fi
done