0

I encountered a problem when reading grep manual refering to it -e option,
It say:

-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
         (`-').

I'm confused about what's the e short for? There's not an answer could searched by google.
Additionally, it's easy to understand that

"This option is most useful when multiple -e options are used to specify multiple patterns"

but what does this mean?

"or when a pattern begins with a dash (`-')."

Could you please show an example?

1
  • e for expression?
    – Wizard
    Apr 4, 2018 at 3:41

1 Answer 1

6

"e for expression" is a reasonable interpretation, especially in contrast to the -E flag for Extended Regular Expression (ERE) which is available in at least some versions of grep.

Multiple -e flags may be used to match any of multiple expressions, e.g.:

# grep -e "nodes" -e "routers" /etc/hosts
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

And -e allows for patterns that begin with a dash, so that grep doesn't try to interpret the pattern as an option/flag:

# grep -e "-all" /etc/hosts
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
ff02::3         ip6-allhosts

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .