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

Re: Alias call in function fails...



On Tue, Jun 23, 2020 at 01:23:55AM +0200, Mikael Magnusson 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

If the alias is defined before the definition of the function, it ought to work.

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



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