On 28/12/2018 11:08, Joerg Schilling wrote:
Harald van Dijk <a...@gigawatt.nl> wrote:
Hi,
Reading <http://austingroupbugs.net/view.php?id=1055#c3292>, I'm very
surprised to discover that how aliases work is being completely
rewritten in a way incompatible with existing shells and existing shell
scripts. No reason is given for this, so I'm asking for one here. I
would have imagined that the point would be to ensure that something like
alias p=echo; p Hello
works, where in existing shells it does not, but that still will not
work even under the new wording.
I am not sure whether I understand you correctly.
The new text is intended to explain that aliases are not usable before they are
set up and a new instance of the lexer is called.
If it's really intended to just explain, not to require any changes in
behaviour, that's great.
I gave the example of
alias mycase=case
mycase x in (x) echo ok ;; esac
I do not see how this is supposed to work under the new wording.
However, looking in more detail, I do not see how this is supposed to
work under the old wording either. Without alias substitution, this is a
syntax error, so arguably "mycase" cannot be "identified to be the
command name word of a simple command" (that's in both old and new wording).
Similarly, both the old and the new wording seem to say that
alias f=#
f()
{
echo bug
}
must print nothing (and define a function named "f"), even though many
shells, yours included, print "bug". Here you don't even get into the
question of whether a complete simple command must be found first: the
"f" on line 2 is a NAME token, not a WORD, even though this cannot be
known until the next token is seen.
Seeing now how all this is not something introduced by the new wording,
I am happy to accept that this is not intended as a change, so thank you
and Mark for your time and explanations. I do think the wording should
be fixed.
This is important in case of e.g. "dot" scripts that are parsed completely
before the interpreter is called and as a side effect, this makes it imposible
to use aliases in a "dot" script that defines them.
That's something else that surprised me. Almost all shells *don't* parse
dot scripts that way. The new wording requires
. /dev/stdin <<EOF
alias echo="echo not"
echo ok
EOF
to print "ok", assuming the obvious meaning of the non-standard
/dev/stdin. Your shell and ksh are pretty much the only ones that do
this. bash, dash, mksh, yash, zsh, they all print "not ok", because they
parse dot scripts as a program, as is currently allowed, but under the
proposed wording will not be.
Cheers,
Harald van Dijk