32

I am trying to grep for a php function call

grep -Ri '->someFunction' .

But it's not working. What am I doing wrong?

Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106

2 Answers2

55

It's not the quotes : try this :

grep -Ri -- '->someFunction' .

the -- part stands for end of options ; it's a shell trick.

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • Thank you! it totally worked! `grep -Ri -- '->someFunction' .` – Drew LeSueur Apr 05 '13 at 14:42
  • 1
    If you're on an old system you have to say '`grep -e`' instead of '`grep --`'. However, greps that old probably don't support `-R`. – zwol Apr 05 '13 at 15:01
  • 2
    Also, it would be better to describe `--` as "end of *options*", not "end of *arguments*". You have got arguments after the `--`, it's just that a leading `-` is no longer special. – zwol Apr 05 '13 at 15:02
-1

This is one of those cases where "it's not working" isn't enough to diagnose the problem.

In your case, the error message you got was

 grep: invalid option -- >

That is your clue to see that ->someFunction is being seen as a command-line switch.

I also suggest that you may want to look at ack, which is meant for this sort of source code searching. In your case, you would do:

ack -i -- '->someFunction'
Andy Lester
  • 91,102
  • 13
  • 100
  • 152