From: Harald van Dijk <harald@gigawatt.nl>
To: Martijn Dekker <martijn@inlv.org>,
DASH shell mailing list <dash@vger.kernel.org>
Subject: Re: Alias/heredoc/cmdsubst regression
Date: Sat, 25 Jan 2020 01:38:34 +0000 [thread overview]
Message-ID: <f40ce455-afd8-05f4-e594-4395bb2a8ed0@gigawatt.nl> (raw)
In-Reply-To: <8b48cd04-b85f-1086-55c8-8e17800f5693@gigawatt.nl>
On 25/01/2020 01:13, Harald van Dijk wrote:
> On 24/01/2020 23:48, Martijn Dekker wrote:
>> There is a regression involving alias expansion, a here-document, and
>> a command substitution. The following worked fine until dash 0.5.8; it
>> throws a syntax error as of dash 0.5.9.
>>
>> alias BEGIN='{' END='}'
>> BEGIN
>> cat <<eof
>> $(echo hi)
>> eof
>> END
>
> Nice find.
>
> When the newline after cat <<eof is seen, checkkwd is changed to
> indicate that the shell is in a state where aliases can be expanded.
> Then, parseheredoc() is called, which in turn calls readtoken1() to
> parse the here-document. readtoken() re-sets checkkwd once it is done,
> but readtoken1() does not, so normally this preserves the "can expand
> aliases" state. However, nested command substitutions do reset checkkwd,
> so things break.
>
> Until 0.5.8, parseheredoc() was called first, and only after that did
> checkkwd get changed.
>
> Either parseheredoc() needs to save and restore checkkwd, or the code
> calling parseheredoc() needs to ensure that it sets checkkwd as
> appropriate afterwards.
There is another place that parseheredoc() can be called from where
checkkwd was not being corrected afterwards:
alias BEGIN='{' END='}'
: <<EOF &&
$(echo hi)
EOF
BEGIN
echo ok
END
This has been failing for longer. This prints "Syntax error: "("
unexpected" since at least 0.5.1.
> Cheers,
> Harald van Dijk
next prev parent reply other threads:[~2020-01-25 1:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-24 23:48 Alias/heredoc/cmdsubst regression Martijn Dekker
2020-01-25 1:13 ` Harald van Dijk
2020-01-25 1:38 ` Harald van Dijk [this message]
2020-01-25 12:19 ` [PATCH] parseheredoc: fix alias expansion: save and restore checkkwd Martijn Dekker
2020-01-25 16:17 ` Harald van Dijk
2020-01-25 16:26 ` Alias/heredoc/cmdsubst regression Martijn Dekker
2020-01-25 16:33 ` Harald van Dijk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f40ce455-afd8-05f4-e594-4395bb2a8ed0@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--cc=martijn@inlv.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).