Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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
1  
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
1  
This is not an answer and I feel stupid telling you this :P –  Oliver Salzburg Jul 23 '12 at 19:16
    
1  
@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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.