【问题标题】:what is =~ in following script [duplicate]以下脚本中的 =~ 是什么 [重复]
【发布时间】:2013-08-08 11:42:27
【问题描述】:

此脚本检查一个目录是否是另一个目录的父目录。如何使用这个脚本?

     T() {
          if [[ "$2" =~ ${1}['/'?] ]] ; then
              echo "$2 is child of $1"
              return 0
          else
              echo "$2 is NOT child of $1 ($?)"
              return 1
          fi
         }

【问题讨论】:

标签: bash shell


【解决方案1】:

这是一个正则表达式匹配,是一个将字符串匹配到模式的有用工具。 This link 可以帮到你。

【讨论】:

    【解决方案2】:

    它是一个正则表达式模式匹配运算符。请参阅Conditional constructs 下的bash 参考手册,并查找[[ ... ]] 构造。

    【讨论】:

      【解决方案3】:

      来自手册:

      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 regex3)). The return value is 0 if the string matches the pattern, 
      and 1 otherwise.
      

      【讨论】:

        猜你喜欢
        • 2014-10-24
        • 2013-04-08
        • 1970-01-01
        • 2021-07-16
        • 1970-01-01
        • 2018-05-11
        • 1970-01-01
        • 1970-01-01
        • 2013-09-14
        相关资源
        最近更新 更多