Generally, you only have to escape one time to make special character considered literal. Sometime you have to do it twice, because your pattern is used by more than one program.
Let's discuss your example:
man gcc | grep \\.
This command is interpreted by two programs, the bash
interpreter and grep
. The first escape causes bash
to know \
is literal, so the second is passed for grep
.
If you escape only one time, \.
, bash
will know this dot is literal, and pass .
to grep
. When grep
see this .
, it thinks the dot is special character, not literal.
If you escape twice, bash
will pass the pattern \.
to grep
. Now grep
knows that it is a literal dot.
man bash|grep \\.
could be a example. – Registered User Jul 16 '14 at 06:31man gcc | grep '\.'
. – Leonid Beschastny Jul 16 '14 at 10:21