Is there a way to test whether an array contains a specified element?
e.g., something like:
array=(one two three) if [ \"one\" in ${array} ]; then ... f
In_array() { local NEEDLE="$1" local ELEMENT shift for ELEMENT; do if [ "$ELEMENT" == "$NEEDLE" ]; then return 0 fi done return 1 } declare -a ARRAY=( "elem1" "elem2" "elem3" ) if In_array "elem1" "${ARRAY[@]}"; then ...
A nice and elegant version of the above.