I want to find the string $foo['bar'] in a directory, with the command grep -Rn . But no matter what I try, I can’t find out what caracter use to avoid regex.
user@server$ grep -Rn $foo['bar'] /lib // obviously don't work
user@server$ grep -Rn "$foo['bar']" /lib // don't work
user@server$ grep -Rn `$foo['bar']` /lib // don't work
user@server$ grep -Rn $foo\['bar'\] /lib // don't work
I have to use grep -Rn command, not another one. Thanks a lot !
You need to escape the [ ] signs, use this:
Note in this context escaping the initial dollar sign is not necessary, but I find it’s clearer that way.