linux - find 命令使用posix-egrep, 不好使
ringa_lee
ringa_lee 2017-04-17 16:19:50
0
1
619

2016/12/8

问题

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

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

相关代码

  • 定制的find命令

find-regex() {
    # find-regex $path $pattern
    if [ $# = 0 ]; then                                                                                     
        echo "Usage: find-regex $path $pattern"
    else
        find "$1" -regextype posix-egrep -regex "$2"
    fi  
}
  • man find

 -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_lee
ringa_lee

ringa_lee

全部回复(1)
左手右手慢动作

用法是没有问题的,之所以没有得到你想要的结果可能是因为 "$2" 双引号包含的$2内的特殊字符有可能会被shell所解释。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!