\h is not a special escape for grep, so '\h' should find a \h in a file, which it does.
The shell removes the first \ before grep sees it, as \ is special (type ls \\ and it says ls: \: So such file or directory ). So to match "\h" in a file, use grep \h, or '\h' to avoid the first \ --> \ reduction by the shell.
Now \$ : \ is reduced to \ by the shell, and grep sees \$ and because $ is special in regexes (like +,.,* etc), \$ is a literal dollar sign, as a simple test file will show you. See the man page for re_format (7). So this matches all lines with a dollar sign.
So if you want to match a literal "\$" in a file, we need to think: \$ is unescaped by the shell to literal $, and \ to \: try ls \\\$' and you get "ls: \$: No such file or directory". So ingrep \\$ file, grep sees \$ and interprets that as $ again... So we want grep to see \\\$ (which it will unescape again to \$), so we can put single quotes around that and avoid headaches, or escape all the special characters for the shell too:grep \\\\$ file`. This works.
That's why I almost always put single quotes around the first grep argument, so I only have to think about what grep will do, and not about the shell as well.
$some special symbol too? Try\\\$– Draco Ater Apr 16 '10 at 11:34\\\\\\\\hjust to see\\\\h. hope i got the numbers right. – quack quixote Apr 16 '10 at 11:53echoto see what input is going intogrep. I.E.,echo \\\$will give output as\$. – Kevin Panko Apr 16 '10 at 15:42