第1个回答 2021-02-05
方法一:利用grep查找
strA="long string"strB="string"result=$(echo $strA | grep "${strB}")if [[ "$result" != "" ]]then echo "包含"else echo "不包含"fi
方法二:利用字符串运算符 《Linux就该这么学》 一起学习linux
strA="helloworld"strB="low"if [[ $strA =~ $strB ]]then echo "包含"else echo "不包含"fi
方法三:利用通配符
A="helloworld"B="low"if [[ $A == *$B* ]]then echo "包含"else echo "不包含"fi