Suppose I have a string,
a="This is a string"
and an array,
b=("This is my" "sstring")
I want to execute an if condition if any substring of a lies in b which is true because "This is" is a substring of the first element of b.
In case of two strings I know how to check if $x is a substring of $y using,
if [[ $y == *$x* ]]; then
#Something
fi
but since $x is an array of strings I don't know how to do it without having to explicitly loop through the array.
iis in them? Is the double s in sstring a typo?ais a substring of "This is my" of the first element ofb, I want a match to occur. The double s is not a typo. I don't want a match by string being a substring of sstring. I am looking for matches only upto words separated by a space.aandb-- according to your comment, you're only looking for space-separated substrings ofa. Does this also apply for matches inb? For example should an entry like "banapple gas" inbmatch, sinceais a space-separated substring ina?ais a substring of any element ofb? Because I would ordinarily be inclined to interpret "lies in [array]b" as "is equal to an element ofb", yet that is not consistent with your example. Note also that your[[ $a == *${b[0]}* ]]would evaluate to false with your example data.