Linux shell if 判断字符串包含子串

方式一:

string='My string';
if [[ $string =~ "My" ]];then
   echo "It's there!"
fi

 

方式二:

string='My long string'
if [[ $string == *"My long"* ]]; then
  echo "It's there!"
fi


上一篇:Be Positive


下一篇:模板字符串