Shell判断字符串是否含有特定字符

场景:判断字符abcde是否含有字符abc

[[ "abcde" =~ "abc" ]] && echo "this is true" || echo "this is not true"


if [[ "abcde" =~ "abc" ]]; then
echo "this is true"
else
echo "this is not true"; exit
fi

发表评论