bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash-5.1-beta available


From: Robert Elz
Subject: Re: Bash-5.1-beta available
Date: Mon, 14 Sep 2020 03:51:40 +0700

    Date:        Sun, 13 Sep 2020 14:29:15 -0400
    From:        Chet Ramey <chet.ramey@case.edu>
    Message-ID:  <a82c61e2-3c3b-7eba-329f-185580fedac7@case.edu>

  | The specific construct is
  |
  | P=A
  | cat <<EOF
  | ${P+\"$P\"}
  | EOF

That should output \"A\"

  | In this case, the usual proscription on double quotes in here-documents
  | does not apply, since the double quote appears within ${}.

Huh?   Where does that come from, at best a " inside a quoted ${} is
unspecified.   But in a here doc, " is simply not a quoting char at all.
There are no special quoting rules in var expansions, other than the
substring extraction versions (the new ones) (and of course, you get to
do whatever you like with all the bash extensions).

  | This change makes the above and
  |
  | echo "${P+\"$P\"}"
  |
  | echo the same thing.

It shouldn't as in that the double-quotes are quoting chars.   There the
\" (both instances) is inside a double quoted string where " is special.
Thus in that one, the \ does escape the ".

  | The bash-5.1 behavior is consistent with what other shells claiming POSIX
  | conformance, except the BSD ash-based shells, produce.

Also not bosh.   It is more consistent with what ksh shells do, and it
turns out dash does that as well (though neither the fbsd nor nbsd shells do).
(zsh claims there is a parse error, but that must just be a bug, or some 
bizarre extension which isn't being used as intended).

  | There's pretty wide
  | variance in behavior between shells with all of the variants of putting a
  | double quote inside a parameter expansion inside a here-document, and
  | POSIX has basically thrown its hands in the air in disgust.

Yes.   But there really is little doubt what is right here, " is not
a quoting char in a here doc (unless a new quoting context gets started,
which it doesn't here), so you should get the same output from:

cat <<EOF
${P+\"$P\"}
EOF

as you would from

cat <<EOF
${P+\@$P\@}
EOF

except with " instead of @ in the output.   Nothing else really makes sense.

Shells that omit the \ from the former, either don't understand that a here
doc (without a quoted end-delim) is a double quoted string, which doesn't
use the double quote char as the quote mark (but the here-doc syntax instead).
Or they don't really follow the rules for \ in a double quoted string.

kre




reply via email to

[Prev in Thread] Current Thread [Next in Thread]