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