码迷,mamicode.com
首页 > 其他好文 > 详细

字符串包含关系判断

时间:2019-01-11 21:19:29      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:res   关系   利用   strong   mic   str   通配符   字符串   soft   

1、利用grep查找

str1="ABC"
str2="A"

result=$(echo $str1 | grep "${str2}")

if [[ "$result" != "" ]];then
    echo "包含"
else
    echo "不包含"
fi

 

2、利用字符串运算符

str1="hellow"
str2="low"

if [[ $str1 =~ $str2 ]];then
    echo "包含"
else
    echo "不包含"
fi

 

3、利用通配符

str1="hellow"
str2="low"

if [[ $str1 == *$str2* ]];then
    echo "包含"
else
    echo "不包含"
fi

 

字符串包含关系判断

标签:res   关系   利用   strong   mic   str   通配符   字符串   soft   

原文地址:https://www.cnblogs.com/t-road/p/10257202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!