EDG EDG - 2 months ago 14
Linux Question

How to grep a file for text with apostrophes?

people... Im coding a linux bash file and I need it to grep for the text

'Josh''1234
. Is there any way to ignore those apostrophes? heres what I tried:
(Josh is set as
usr
and 1234 as
pas
.)

if grep -q '\'$usr\'\'$pas\''; then
echo username and password correct
else
echo INCORECT
sleep 10
fi

Answer

Just quote with double quotes, so that single quotes can be included normally:

grep "'$usr''$pas"
#    ^           ^
#     ^    ^^
#     single quotes to match