Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Alias call in function fails...
> On 23 June 2020 at 09:37 Andreas Kusalananda Kähäri <andreas.kahari@xxxxxx> wrote:
> 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???
>>
>> 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).
>
> If the alias is defined before the definition of the function, it ought to work.
It's a bit more complicated than that. There's a difference between a file
that's being executed line by line, which includes initialisation files
and sourced files as well as scripts, and a file that's parsed and then executed,
which would include an autoloaded function definition. In the former case,
the alias is defined before the function definition is executed; in the latter
case it isn't, even though the line with the alias definitions appears before
the function definition.
For sure you can't define the alias *after* the function definition.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author