首頁  >  問答  >  主體

linux - find 命令使用posix-egrep, 不好使

2016/12/8

问题

根据我的了解, find中一般使用shell通配符, 但是shell通配符的表达能力不是很强, 所以就想使用正则, 但是结果不如人意.

查阅了文档, 自认为是按照文档的描述做的, 不知问题出在何处.

相关代码

find-regex() {
    # find-regex $path $pattern
    if [ $# = 0 ]; then                                                                                     
        echo "Usage: find-regex $path $pattern"
    else
        find "$1" -regextype posix-egrep -regex "$2"
    fi  
}
 -regextype type
              Changes the regular expression syntax understood by -regex and -iregex  tests  which  occur
              later  on  the  command line.  Currently-implemented types are emacs (this is the default),
              posix-awk, posix-basic, posix-egrep and posix-extended.
ringa_leeringa_lee2715 天前680

全部回覆(1)我來回復

  • ringa_lee

    ringa_lee2017-04-17 16:21:50

    用法是沒有問題的,之所以沒有得到你想要的結果可能是因為 "" 雙引號包含的$2內的特殊字符有可能會被shell所解釋。

    回覆
    0
  • 取消回覆