先打印长字符串,然后在长字符串中 grep 查找要搜索的字符串,用变量result记录结果
如果结果不为空,说明strA包含strB。如果结果为空,说明不包含。
这个方法充分利用了grep 的特性,最为简洁。
方法二:利用字符串运算符
strA=“helloworld”
strB=“low”
if [[ $strA =~ $strB ]]
then
echo “包含”
else
echo “不包含”
fi
利用字符串运算符 =~ 直接判断strA是否包含strB。(这不是比第一个方法还要简洁吗摔!)
方法三:利用通配符
A=“helloworld”
B=“low”
if [[ A = = ∗ A == * A