grep for a backslash question

Why does this work when grepping for a backslash?

grep '\\' .bash_history
grep "[\\]" .bash_history

Why does this not work when grepping for a backslash?

grep "\\" .bash_history

I know this works works but just don't understand why I need 4 backslashes when using double quotes.

grep "\\\\" .bash_history

Try

$ echo '\\'
\\
$ echo "\\"
\
$

double-quotes use backslashes themselves to escape things like other double quotes.

So single quotes take you literally and double quotes keep their special meaning?

Essentially yes. Expansion does not happen within single quotes but does within double quotes.

The grep command requires a \\ to mean \, also in shell's double quote and non-quote. So When you Use \\ or "\\" in shell, a \ will be passed to grep. Since \ is an escape char in grep, a single \ does not match any char. So If you use "\\\\", it works.

And expansion turns two backslashes into a single backslash right?

Am I right to assume that there is expansion with this?

$ echo \\
\

How else do you prevent expansion besides with single quotes?

Is this because of expansion like fpmurphy just mentioned?

@ And expansion turns two backslashes into a single backslash right?
yes.

@ How else do you prevent expansion besides with single quotes?
You can't.

@ Is this because of expansion like fpmurphy just mentioned?
Yes.

IMO, the shell syntax is badly desinged, since they are confusing. But, they are rigorous. You can grasp them in practice.
see also:
[Chapter 7] 7.3 Command-line Processing
and the command 'eval'

Thx :).

I love the trial and error method :). I do that a a lot.