Bash 正则表达式 =~ 运算符 [英] Bash regex =~ operator
问题描述
=~
运算符叫什么?是不是只用来比较右边和左边?
为什么在运行测试时需要双方括号?
即.[[ $phrase =~ $keyword ]]
谢谢
- <块引用>
=~
运算符叫什么?我不确定它有没有名字.bash 文档 只是将其称为
=~
运算符. - <块引用>
是否仅用于比较右侧和左侧?
右侧被认为是扩展的正则表达式.如果左侧匹配,则运算符返回
0
,否则返回1
. - <块引用>
为什么在运行测试时需要双方括号?
因为
=~
是[[表达式]]
复合命令的操作符.
What is the operator =~
called? Is it only used to compare the right side against the left side?
Why are double square brackets required when running a test?
ie. [[ $phrase =~ $keyword ]]
Thank you
-
What is the operator
=~
called?I'm not sure it has a name. The bash documentation just calls it the
=~
operator. -
Is it only used to compare the right side against the left side?
The right side is considered an extended regular expression. If the left side matches, the operator returns
0
, and1
otherwise. -
Why are double square brackets required when running a test?
Because
=~
is an operator of the[[ expression ]]
compound command.
这篇关于Bash 正则表达式 =~ 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!