check wheter a string contains a substring bash script code example
Example 1: checking if a substring exists in a string bash
string='Haystack';
if [[ $string =~ "Needle" ]]
then
echo "It's there!"
fi
Example 2: bash if substring
string='Hi substring' #To check if string has "Mylong" substring do
if [[ $string == *"substring"* ]]; then
echo "String has substring"
fi