I want to grep for a variable that has the string test
, but I also want to make sure that it will only find test
if that is the only word on a line.
So, I tried this:
string=test
echo "test" | grep "$string$"
I would like to know if grep
knows that the first part, $string
(in grep "$string$"), is asking to find for the string test
, while the last part, $
(in grep "$string $" is asking to find for test
, but nothing should be after test
in the line. Is grep
able to distinguish $string
as a variable and only $
as the regex for end of the line, or do I have to use a certain way to distinguish them apart?