使用grep
s1="abcdefg"
s2="bcd"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" != "" ]]
then
echo "$s1 include $s2"
else
echo "$1 not include $s2"
fi
使用操作符~
fileName=/home/sss/data/hk
if [[ $fileName =~hk ]]
then
echo "$fileName include hk"
else
echo "not include"
fi
使用通配符*
A="helloworld"
B="low"
if [[ $A == *$B* ]]
then
echo "包含"
else
echo "不包含"
fi
GitHub : https://github.com/fxiaoyu97
微信公众号 : 三更编程菌
作者:卡洛小豆