19

I've seen several instances where people are doing this:

grep [f]oobar

But I don't understand why that is preferable to

grep foobar
hippietrail
  • 105
  • 4
hortitude
  • 565
  • 1
  • 3
  • 10
  • Hmm .. I thought it is supposed to match range of characters within the []. If it is just a single character, it could be just to make it look complicated :) Maybe there is something more to it. – Chida Aug 22 '12 at 19:45
  • Something so simple can be so beautiful – Chida Aug 22 '12 at 19:55

1 Answers1

33

There's no reason that's preferable syntax on its own. It's sometimes used as a hack when "grepping" for a process (e.g., ps aux | grep [a]pache). Using that syntax prevents grep from matching its own command line in the process list.

See How to prevent "ps" reporting its own process?

Jeff Ferland
  • 20,239
  • 2
  • 61
  • 85