You could use the following function :
function IsInList {
local i
for i in "${@:2}"; do
[ "$i" = "$1" ] && return 0
done
return 1
}
for CLIENT in "${LIST[@]}"; do
IsInList "$CLIENT" "${server_client_list[@]}" && echo "It's in the list!"
done
Note that the quotes around ${LIST[@]}
and ${server_client_list[@]}
are very important because they guarantee the array expansion to expand the way you want them to, instead of having a bad surprise when a space make its way into one of those array values.
Credits : I took this function from patrik's answer in this post when I needed something like that.
Edit :
If you were looking for something with regexp capabilities, you could also use the following :
function IsInList {
local i
for i in "${@:2}"; do
expr match "$i" "$1" && return 0
done
return 1
}