1.使用grep

s1="helloworld"
s2="ello"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" != "" ]]
then
    echo "$s1 include $s2"
else
    echo "$1 not include $s2"
fi

2. 使用操作符~

fileName=/home/sss/data/cl

if [[ $fileName =~cl ]]
then
    echo "$fileName include cl"
else
    echo "not include"
fi

3. 使用通配符*

A="helloworld"
B="low"
if [[ $A == *$B* ]]
then
    echo "包含"
else
    echo "不包含"
fi

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2020-04-08
  • 2021-07-25
  • 2021-05-31
  • 2022-12-23
  • 2021-06-06
  • 2022-03-05
猜你喜欢
  • 2022-12-23
  • 2021-06-20
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案