In the shell, interpret whether there is a certain character in the string (ignoring case)

search_1='hello'
search_2='Hello'
str='helloworld'
if [[ $str =~ $search_1 ]]
then
   echo 'get search_1'
be
if [[ $str =~ $search_2 ]]
then
   echo 'get search_2'
be
#Ignore case just convert to upper case or lower case first
search_3=$(echo $search_2 | tr '[A-Z]' '[a-z]')
echo $search_3
if [[ $str =~ $search_3 ]]
then
   echo 'get search_3'
be

Here you need to focus on the usage of the tr command http://man.linuxde.net/tr

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326895709&siteId=291194637