Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zcompile does not expand aliases defined in the compiled script
- X-seq: zsh-workers 46210
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Subject: Re: zcompile does not expand aliases defined in the compiled script
- Date: Tue, 7 Jul 2020 22:28:24 +0200
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- In-reply-to: <CAN=4vMrevv626MrDG=yaqJKOjs_6ayQVfiaUBBmj+yHbsn+6cw@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAN=4vMrevv626MrDG=yaqJKOjs_6ayQVfiaUBBmj+yHbsn+6cw@mail.gmail.com>
- Sender: zsh-workers@xxxxxxx
On 7/7/20, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
> I naively expected that `zcompile x && source x` has the same effect
> as plain `source x` but apparently when using the former aliases
> defined within `x` aren't expanded during the evaluation of `x`.
>
> Is this expected behavior?
>
> % zsh -f
> % print 'alias x=:; x' >x
> % zcompile x
> % source x
> x:1: command not found: x
It is expected, but you are not correct that it works when you didn't
compile the file first:
% source x
zsh: command not found: x
However, sourcing a non-compiled file multiple times will of course
work on subsequent runs because the alias is carried across in the
shell session. If you zcompile the file after sourcing it once, it
will also work subsequently (even in new sessions) as aliases, if any,
are expanded at compile time (unless inhibited by -U).
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, since it is
parsed and executed line by line. This does not change anything for
the zcompile case from the above paragraph as the entire file is
parsed and nothing is executed.
Hopefully all of the above is true, I did my best to test it :).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author