[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Probably not a bug but I was surprised: $' does not work inside "...
From: |
Greg Wooledge |
Subject: |
Re: Probably not a bug but I was surprised: $' does not work inside "..." close. |
Date: |
Thu, 18 Mar 2021 07:38:03 -0400 |
On Wed, Mar 17, 2021 at 09:11:48PM -0400, Dale R. Worley wrote:
> I have it encoded in my head that $ inside "..." is respected. Subtly,
> the $'...' construction is not respected inside "...".
Bash has 5 types of quoting: '...', "...", $'...', $"..." and backslash.
$'...' is a form of quoting, not an expansion. It won't "work" inside
of another type of quoting, just like '...' will not "work" inside "...".
echo "foo is '$foo'"
In this example, $foo is expanded, despite the fact that there are
single quotes around it, because the single quotes have no meaning in
this context. They're inside a *different* type of quoting, so they
are just regular literal characters.
The only exception here is backslash, which retains its special powers
when inside "..." or $"...".