3

I wanted to find $featuredicon variable in my php files, and I ran grep -ir "$featuredicon"

I understood that dollar sign is reserved character in shell. But what does it actually do? Did I modify my php files? I'm afraid I did something bad...

next time I will run grep -ir "\$featuredicon"

1
  • Welcome to Super User. Remember to accept the answer that actually answers your question, which is not necessarily the first answer you receive. Jul 23, 2012 at 20:31

2 Answers 2

4

The reason why every single line of every single file was listed was due to variable substitution of your shell.

When you call

grep -ir "$featuredicon" *

bash will evaluate that. It will look up the variable $featuredicon and put it into your command. Guess what $featuredicon most likely is?

Right, nothing. So what you're actually doing is:

grep -ir "" *

And that matches every line of every file.

Old Answer

The dollar sign ($) is a placeholder for end-of-line in regular expression (I assume the same is true for grep).

If you want to search for a dollar sign, use '\$'.

Be sure to check the StackOverflow question: How to grep for the dollar symbol ($)?

3
  • Ty, escaping part I figured it out myself.
    – user98645
    Jul 23, 2012 at 20:29
  • I was just curious what it did to my php files, or why it was outputing everything to terminal.
    – user98645
    Jul 23, 2012 at 20:30
  • @SandroDzneladze: I updated my answer to address your specific concerns. I was misinterpreting your issue. Jul 23, 2012 at 21:37
1

grep cannot modify files on its own; it has caused no damage.

5

You must log in to answer this question.