Check if an array contains a given string:
teams=(chiefs broncos chargers raiders) if [[ ${teams[*]} =~ broncos ]] then echo "VICTORY!" fi
Or, if you don’t want it to contain the string then:
teams=(cardinals 49ers seahawks rams) if [[ ${teams[*]} =~ broncos ]] then echo "This conference sucks" else echo "VICTORY!" fi
WRONG!
It doesn’t work if you try to check if the array contains “b” (I mean, the result would be yes).
The right solution is include boundaries caractères to the regexp : “\b”
search=\\bbroncos\\b
if [[ ${teams[*]} =~ $search ]]
then
echo “VICTORY!”
fi