Home > OS >  Use variable with string (with spaces) as value in grep
Use variable with string (with spaces) as value in grep

Time:12-02

My variable $pepe has the name of a file (with spaces) as value, and I want to use the grep command to find that file in ls -l. The problem is that I can literally write it but I cannot use it if its set inside $pepe.

In the image you can see what I tried.

CodePudding user response:

You must duble quote and use interpolation in this case:

ls -l | grep echo "${pepe}"

CodePudding user response:

This

ls -l | grep "`echo ${pepe}`"

This worked for me.

  • Related