0

I have saved the path in the variable .

var="/home/myfolder/subfolder"

Need to search whether the path in available in a text file using grep.

grep -l '${var}' * >abc.txt

I'm trying to list the file names which has the above path but it's not working. How to search for path in a file using grep?

1
  • Using double quote instead of single quote grep -Fl "${var}". -F for fixed string instead of regex. – cuonglm Sep 3 '15 at 10:36
1

Variables are not expanded to values when they are put within single quotes, they are treated literally then.

You need to use double quotes :

grep -l -- "${var}" *

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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