I have a use case where a variable needs to be checked with multiple sub-strings in OR-condition and produce an output; as below:
if [ ! -z "$var" ]; then
if [[ $var =~ .*Focus.* ]] || [[ $var =~ .*Wallet.* ]]; then
ser=`echo $var|cut -d ' ' -f 2`
echo " $ser is correct"
else
ser=`echo $var|cut -d ' ' -f 2`
echo "!!!! $ser is incorrect !!!!"
fi
fi
var
contains pid and ServiceName. ServiceName is being checked if it contains any of the both substrings. It is running perfectly fine. But I want var
to be checked in a list of substrings mentioned in a file instead, so that file can be modified later for more substrings.