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

Re: Problem with alias in 'if' blocks



Brady Morgan wrote:
>Can someone explain why the alias isn't "known" until I'm out of the
>"if" loop?  Also, if I've goofed with this, could someone demonstrate
>the proper way to achieve the desired result.

Aliases are expanded when commands are first scanned, not when they are
executed.  The entire if construct has to be read in and parsed before
it can be executed at all, so the aliases expanded in it are those in
effect at the start of the construct.

The solution is to use a shell function, rather than an alias.  The
behaviour of functions is better defined, and more like normal
commands.  Aliases are really only useful interactively.

-zefram



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