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
2
  • 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, 2012 at 19:45
  • Something so simple can be so beautiful
    – Chida
    Aug 22, 2012 at 19:55

1 Answer 1

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?

2
  • 4
    That's the only common example of that syntax I'm familiar with.
    – ewwhite
    Aug 22, 2012 at 19:57
  • In fact, you are right. The last several examples I ran across were from a "ps exclusion"
    – hortitude
    Aug 23, 2012 at 15:39

You must log in to answer this question.

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