The goal is to verify if the string matches any of list item.
This is opposite to CHECK IF VARIABLE EXISTS in the list
Code should be similar to:
email="john.brown@google.com"
list=["app-1", "app-2", "john"]
if [ $email -contains $list]; then
echo "email contains variable from list"
else
echo "email does not contain any of list items"
fi
# Item1: false -> email does not contains "app-1"
# Item2: false -> email does not contains "app-2"
# Item3: true -> email contains "john"
>Solution :
Try with:
#!/bin/bash
email="john.brown@google.com"
list=("app-1" "app-2" "john")
found=false
for item in "${list[@]}"; do
if [[ $email == *"$item"* ]]; then
echo "Found!"
found=true
break
fi
done
if [ $found == false ]; then
echo "Not found."
fi