In Bash, what is the simplest way to test if an array contains a certain value?
printf '%s\n' "${myarray[@]}" | grep -P '^mypattern$'
Explanation
The printf statement prints each element of the array on a separate line.
The grep statement uses the special characters ^ and $ to find a line that contains exactly the pattern given as mypattern (no more, no less).
Usage
To put this into an if ... then statement:
if printf '%s\n' "${myarray[@]}" | grep -q -P '^mypattern$'; then
# ...
fi
I added a -q flag to the grep expression so that it won't print matches; it will just treat the existence of a match as "true."