dotancohen dotancohen - 6 months ago 10
Linux Question

Grep not as a regular expression

I need to search for a PHP variable

$someVar
. However, Grep thinks that I am trying to run a regex and is complaining:

$ grep -ir "Something Here" * | grep $someVar
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
$ grep -ir "Something Here" * | grep "$someVar"
<<Here it returns all rows with "someVar", not only those with "$someVar">>


I don't see an option for telling grep not to interpret the string as a regex, but to include the
$
as just another string character.

Answer

Escape the $ by putting a \ in front of it.