# Created on savesnippets.com ยท https://savesnippets.com/6qoHacAeTXM0Yy arr=("alice" "bob" "carol") target="bob" # Method 1: explicit loop (clearest) contains() { local needle="$1"; shift for x in "$@"; do [[ "$x" == "$needle" ]] && return 0 done return 1 } if contains "$target" "${arr[@]}"; then echo "yes" fi # Method 2: glue + regex (concise but tricky with separators) [[ " ${arr[*]} " =~ " $target " ]] && echo "yes (regex)"