我在阅读grep
手册时遇到了一个问题,提到它的-e
选项,
它说:
-e pattern, --regexp=pattern
Specify a pattern used during the search of the input: an input
line is selected if it matches any of the specified patterns.
This option is most useful when multiple -e options are used to
specify multiple patterns, or when a pattern begins with a dash
(`-').
Run Code Online (Sandbox Code Playgroud)
我对e
缩写是什么感到困惑?谷歌搜索不到答案。
此外,很容易理解的是
“当使用多个 -e 选项指定多个模式时,此选项最有用”
但是,这是什么意思?
"或者当模式以破折号 (`-') 开头时。"
你能举个例子吗?
“e for expression”是一个合理的解释,特别是与-E
扩展正则表达式 (ERE)的标志形成对比,该标志至少在grep
.
多个-e
标志可用于匹配多个表达式中的任何一个,例如:
# grep -e "nodes" -e "routers" /etc/hosts
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Run Code Online (Sandbox Code Playgroud)
并-e
允许以破折号开头的模式,因此grep
不会尝试将模式解释为选项/标志:
# grep -e "-all" /etc/hosts
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Run Code Online (Sandbox Code Playgroud)