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

要回复问题请先登录注册