shell字符串包含的5种判断方法:
方法一:
strA='long string'
strB='string'
result=$(echo $strA | grep '${strB}')
if [[ '$result' != '' ]]
then
echo '包含'
else
echo '不包含'
fi
方法二(亲测可以):
strA='helloworld'
strB='low'
if [[ $strA =~ $strB ]]
then
echo '包含'
else
echo '不包含'
fi
方法三:
A='helloworld'
B='low'
if [[ $A == *$B* ]]
then
echo '
方法一:
strA='long string'
strB='string'
result=$(echo $strA | grep '${strB}')
if [[ '$result' != '' ]]
then
else
fi
方法二(亲测可以):
strA='helloworld'
strB='low'
if [[ $strA =~ $strB ]]
then
else
fi
方法三:
A='helloworld'
B='low'
if [[ $A == *$B* ]]
then
