str="this is a string" [[ $str =~ "this" ]] && echo "$str contains this" [[ $str =~ "that" ]] || echo "$str does NOT contain that"
结果为:
this is a string contains this
this is a string does NOT contains that
[[" 判断命令和 "=~"正则式匹配符号
str="this is a string" [[ $str =~ "this" ]] && echo "$str contains this" [[ $str =~ "that" ]] || echo "$str does NOT contain that"
结果为:
this is a string contains this
this is a string does NOT contains that
[[" 判断命令和 "=~"正则式匹配符号