I want to ack for the literal string: "$$
" in a code base, but escaping the dollar sign like this:
ack \$\$
doesn't work.
You are getting confused by shell quoting. When you type:
ack "\\\$\\\$\("
the shell interpolates the double quoted string so that \\
is translated to \
, \$
is translated to $
and \(
is translated to \(
and ack gets the string \$\$\(
as its argument. It is much simpler to avoid the shell interpolation by using single quotes and invoke:
ack '\$\$\('
Replace ack
with echo
to explore how the shell is expanding the strings. Note that
ack "\\$\\$\("
will also work, but for slightly different reasons. Here, the first two \
are treated as a single (escaped) \
, then the $
is translated as a $
because it is followed by a character that is not a valid character in a variable name. \(
expands to \(
instead of simply (
because (
is not subject to interpolation and therefore does not need to be escaped. But note that outside of double quotes, \(
is converted to (
.
Shell quoting rules get confusing sometimes!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With