How can I search (escape) a dollar sign with ack?

I want to get the string for the string: " $$" in the code base, but avoiding the dollar sign as follows:

ack \$\$

does not work.

+5
source share
4 answers

You are confused in quoting the shell. When entering:

ack "\\\$\\\$\("

the shell interpolates the double-quoted string, so it \\translates to \, \$translates to, $and \(translates to \(, and ack receives the string \$\$\(as its argument. It is much easier to avoid shell interpolation with single quotes and call:

ack '\$\$\('

Replace ackwith echoto find out how the shell expands strings. note that

ack "\\$\\$\("

, . \ () \, $ $, , . \( \( (, ( , , . , \( (.

!

+16

ack -Q .

ack -Q '$$'
+15

, :

ack "\\\$\\\$"

, :

ack '\$\$'
0

printf, , %q.

$ printf %q '$$('
\$\$\(

help print should say (i guess bash here) `

 %q quote the argument in a way that can be reused as shell input
0
source

All Articles