d
Amit DhamuSoftware Engineer
 

Bash - If In Array

1 minute read 00000 views
ARRAY=(foo bar baz qux)
SEARCH="qux"
NOPE="nope"

if [[ "${ARRAY[@]}" =~ "${SEARCH}" ]]; then
    echo "YES, qux is in the array"
fi

if [[ ! "${ARRAY[@]}" =~ "${NOPE}" ]]; then
    echo "No, nope is NOT in the array"
fi