I'm sure this is a duplicate of some question but I can't find it.
On Unix SE https://unix.stackexchange.com/questions/583428/why-do-i-have-to-quote-an-escaped-character-in-a-regular-expression-for-grep-bu
When you use grep b..l\.txt
, the shell converts \.
into .
so grep receives b..l.txt
, then it interprets .
as any character.
To prevent this, the easiest method is giving grep a string like grep 'b..l\.txt'
, then the shell won't escape the dot. Note that single quotes and double quotes do different things in bash but that doesn't matter in this case. Alternatively, use double backslash so the shell escapes the backslash as a literal character and grep correctly receives \.
.
ls . | grep b..l\\.txt
works and also thisls . | b..l"\.".txt
. Is this what you meant? Could you explain mean what is happening here or point me to relevant resources. @qwr