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

Re: Alias call in function fails...



I once was testing with Eric on IRC and the aliases sometimes do work
within the same file. I think that the distance between the definition and
usage is important. I wonder why? Are the scripts (zshrc in this case)
being parsed in an advancing manner?


On Tue, 23 Jun 2020 at 01:25, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:

> On 6/22/20, Frank Gallacher <franxg@xxxxxxxxx> wrote:
> > Greetings,
> >
> > I have a function:
> >
> [...]
> >
> > Which calls an alias:
> >
> > alias dumpit='hexdump -C -n 128'
> >
> > It works fine in bash, but with zsh now I get:
> >
> > :::::::: test.txt ::::::::
> > dumpall:11: command not found: dumpit
> >
> > Am I doing something wrong???
>
> Yes, don't use aliases for anything but interactive usage. Eg if you
> want to use dumpit in a script, make it be a function:
> dumpit() { hexdump -C -n 128 }
>
> Aliases are expanded on parse time, which means aliases defined in a
> file won't be usable in that same file. (Because it is parsed in its
> entirety before any of the code is actually run).
>
> --
> Mikael Magnusson
>


-- 
Sebastian Gniazdowski
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org


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