=~ 是什么意思?

=~ 是什么意思?

遇到一个 shell 脚本,其中条件语句中有“=~”,我想知道它是什么意思。在 Google 或 SO 网站上运气不佳。

例子:

if [[ $VAR =~ 'this string' ]]

答案1

它是一个正则表达式匹配运算符。

bash手册页:

An additional binary operator, =~, is available, with the same
precedence as == and !=.  When it is used, the string to the
right of the operator is considered an extended regular
expression and matched accordingly (as in regex(3)).  The return
value is 0 if the string matches the pattern, and 1 otherwise.

有关更多详细信息,请参阅bash的手册页(搜索=~

相关内容