Bash 正则表达式 =~ 运算符 [英] Bash regex =~ operator

查看:39
本文介绍了Bash 正则表达式 =~ 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

=~ 运算符叫什么?是不是只用来比较右边和左边?

为什么在运行测试时需要双方括号?

即.[[ $phrase =~ $keyword ]]

谢谢

解决方案

  1. <块引用>

    =~ 运算符叫什么?

    我不确定它有没有名字.bash 文档 只是将其称为 =~ 运算符.

  2. <块引用>

    是否仅用于比较右侧和左侧?

    右侧被认为是扩展的正则表达式.如果左侧匹配,则运算符返回 0,否则返回 1.

  3. <块引用>

    为什么在运行测试时需要双方括号?

    因为=~[[表达式]]复合命令的操作符.

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

解决方案

  1. What is the operator =~ called?

    I'm not sure it has a name. The bash documentation just calls it the =~ operator.

  2. 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, and 1 otherwise.

  3. Why are double square brackets required when running a test?

    Because =~ is an operator of the [[ expression ]] compound command.

这篇关于Bash 正则表达式 =~ 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆