`

shell中判读字符串中是否有某字符(忽略大小写)

 
阅读更多
search_1='hello'
search_2='Hello'
str='helloworld'
if [[ $str =~ $search_1 ]]
then
   echo 'get search_1'
fi
if [[ $str =~ $search_2 ]]
then
   echo 'get search_2'
fi
#忽略大小写只是先转化为大小或小写
search_3=$(echo $search_2 | tr '[A-Z]' '[a-z]')
echo $search_3
if [[ $str =~ $search_3 ]]
then
   echo 'get search_3'
fi

这里需要重点了解 tr 命令的用法 http://man.linuxde.net/tr
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics