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/
#
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175

3 Answers3

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/
Zoredache
  • 3,580
  • 7
  • 29
  • 37
1

use single quotes, like following:

grep 'foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/' /vaw/www/htpasswd
alexus
  • 986
  • 5
  • 16
  • 31
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

austinian
  • 166
  • 3