From: Harald van Dijk <harald@gigawatt.nl>
To: DASH shell mailing list <dash@vger.kernel.org>
Subject: Another alias substitution bug, now involving case statements
Date: Sat, 25 Jan 2020 17:29:20 +0000 [thread overview]
Message-ID: <f35c1096-18b2-f438-f6d7-19c9d5e335ab@gigawatt.nl> (raw)
Hi,
Checking alias substitution handling in more detail after Martijn
Dekker's report, I found another case where I believe dash's behaviour
is incorrect. First, please consider this test:
alias a="case x in " b=x
a b) echo hi ;; esac
bash, ksh and pdksh never check whether a case pattern is a valid alias
name, so they print nothing.
bosh, dash, mksh, yash and zsh do allow the space at the end of a's
definition to cause b to be considered as an alias name.
Based on the literal text of the current standard, I believe
bash/ksh/pdksh's behaviour is correct. Based on accepted new wording for
the standard, new wording that was drafted without considering this
special case, I believe the bosh/dash/mksh/yash/zsh behaviour is
correct. I would not at this time consider this a bug in any of the shells.
Now, consider this modified version:
alias a="case x in " b=x
a
b) echo hi ;; esac
Here, the next token after "a" is a newline token, not b. Here, b must
definitely not be considered as an alias name. bosh, dash, mksh and zsh
do perform alias substitution anyway, yash does not.
The problem here is in the "eat newlines" behaviour of readtoken().
There are two reasons why CHKALIAS might be set. It might be set because
the parser is in a state where the next token could be the start of a
simple command, or it might be set because the parser processed a blank
at the end of a prior alias definition. In the first case, after eating
a newline, the parser is still in a state where the next token could be
the start of a simple command, so CHKALIAS should not be dropped. In the
second case, the blank should only affect a single token, and upon
eating a newline CHKALIAS should be dropped. readtoken() has no way of
distinguishing between these two cases with just a single CHKALIAS flag,
so this will require a bit more complicated work to fix.
Cheers,
Harald van Dijk
next reply other threads:[~2020-01-25 17:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-25 17:29 Harald van Dijk [this message]
2020-01-25 17:55 ` Another alias substitution bug, now involving case statements 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=f35c1096-18b2-f438-f6d7-19c9d5e335ab@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.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 read-only IMAP folder(s) and NNTP newsgroup(s).