Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

share|improve this question
Welcome to Super User. Remember to accept the answer that actually answers your question, which is not necessarily the first answer you receive. – Michael Hampton Jul 23 '12 at 20:31
up vote 4 down vote accepted

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 ($)?

share|improve this answer
Ty, escaping part I figured it out myself. – Sandro Dzneladze Jul 23 '12 at 20:29
I was just curious what it did to my php files, or why it was outputing everything to terminal. – Sandro Dzneladze Jul 23 '12 at 20:30
@SandroDzneladze: I updated my answer to address your specific concerns. I was misinterpreting your issue. – Oliver Salzburg Jul 23 '12 at 21:37

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

share|improve this answer
But what does it do? why did it print all lines from every single file? And how to use $ in grep for what purpose? ty for putting my ocd mind to ease :) – Sandro Dzneladze Jul 23 '12 at 19:13
This is not an answer and I feel stupid telling you this :P – Oliver Salzburg Jul 23 '12 at 19:16
@Oliver: "Did I modify my php files?" – Ignacio Vazquez-Abrams Jul 23 '12 at 19:17
@IgnacioVazquez-Abrams: I guess, you're right. Sorry for judging too quickly. – Oliver Salzburg Jul 23 '12 at 19:27

You must log in to answer this question.

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