Date: Mon, 24 Jan 2022 12:03:39 -0500
From: Chet Ramey <[email protected]>
Message-ID: <[email protected]>
| Except it's not unconditional. You have to accommodate ${x#$'value'} in
| the here-document expansion path because "${x#$'value'}" is processed for
| escape sequences. You're right that it should not be treated differently,
| but it's not as simple as leaving $'...' and $"..." unmodified.
Quite correct, here docs (with unquoted delim word on the redirect operator)
are read exactly the same as double-quoted strings (except " is just a
character, nothing special at all, including \" resulting in 2 chars, not one).
>From a non-bash sh ...
$ x=abcdef
$ cat <<EOF
${x#$'abc'}
EOF
def
$
No escape chars used there, but if they had been, they would have worked,
as the word after the # (or % and ## %% of course) is parsed in its own
quoting context, regardless of what the context is of the overall expansion.
And, of course:
$ cat <<EOF
$'abc'
EOF
$'abc'
$
I should have changed PS1 away from being '$ ' I guess, let me do those
two again with PS1='<%> ' just to avoid any ambiguity...
$ PS1='<%> '
<%> cat <<EOF
${x#$'abc'}
EOF
def
<%> cat <<EOF
$'abc'
EOF
$'abc'
<%>
(I didn't bother to repeat the initialisation of x - nothing changed it).
kre