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

Re: zcompile does not expand aliases defined in the compiled script



On 7/8/20, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
> On Tue, Jul 7, 2020 at 10:28 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> It is possible that you changed the example in the mail without trying
>> what you changed; if you have the statements
>> alias x=:
>> x
>> in the file x, then sourcing it (non-compiled) will work
>
> Yes, that's exactly it. Given a script like this:
>
>   alias x=:
>   x
>
> Sourcing it without zcompile works (`x` on the second line is
> alias-expanded), but once the script is zcompiled an attempt to source
> it results in an error (`x` doesn't get expanded).
>
> I looked at the source code of zcompile and I understand why this
> happens. It makes perfect sense when zcompiling functions. It is,
> however, surprising when zcompiling scripts.

In general it is a good idea to not use aliases in scripts and/or
functions, they are mostly intended to save typing interactively.
Small details such as the above are another reason.

-- 
Mikael Magnusson



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