0

I have a file with this contents (or similar):

# cat /var/www/htpasswd
foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/

and I'm trying to verify the presence of an entry in it, by matching it, like this:

# grep --fixed-string "foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/" /var/www/htpasswd
#

but it's not matching anything. Any ideas why and/or how to do it?

I first I thought it was the dollar sign, but this one works:

# grep --fixed-string "foo:$ap" /var/www/htpasswd
foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/
#
0

3 Answers 3

1

Use single quotes (') so $nnn isn't treated as a variable. Strings with " are interpolated strings, with a ' no interpolation happens.

Heck just just look at the output when you prefeace that string with echo.

$ echo "foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/"
foo:3wJ8tiQ/
$ echo 'foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/'
foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/
1

use single quotes, like following:

grep 'foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/' /vaw/www/htpasswd
1

You should use single quotes instead of double quotes for the --fixed-strings argument to avoid issues with the shell you're using interpreting the results before grep gets to it: https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash

grep --fixed-string 'foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/' /var/www/htpasswd

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