Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How should empty aliases work?

On Fri, 29 Dec 2017 17:14:38 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Fri, Dec 29, 2017 at 12:30 AM, Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > % alias empty=''
> > % alias output='empty echo'
> > % alias echo='print -r bar'
> > % output foo
> >
> > What actually happens is that "echo" expands and "print -r bar foo" is
> > executed.  If that's correct, can someone explain why?
> I think the answer is that being a word in command position has
> precedence over being a word preceded by an alias replacement.  Words
> in command position are always alias-replaceable; words not in command
> position are alias-replaceable if preceded by an alias replacement
> that ended with a space.
> So when "empty" disappears, it leaves "echo" in command position and
> the first clause applies even though the second clause does not.

Yes, when we get to "echo" we have no remaining knowledge that we've
expanded an alias.  The documentation simply refers to an alias being
expanded "if it is in command position [or a global alias]", with no
reference to preceding aliases.  So I think everything is as it should

Consider also

alias foo="echo alias expanded;"

% foo foo
alias expanded
alias expanded

which is just following the same rules.


Messages sorted by: Reverse Date, Date, Thread, Author