Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A couple of bugs in zsh-3.0.7
- X-seq: zsh-workers 8704
- From: Zefram <zefram@xxxxxxxx>
- To: james@xxxxxxx
- Subject: Re: A couple of bugs in zsh-3.0.7
- Date: Sun, 21 Nov 1999 22:41:37 +0000 (GMT)
- Cc: zsh-workers@xxxxxxxxxxxxxx
- In-reply-to: <nnr9hj5vub.fsf@xxxxxxxxxxxx> from James Antill at "Nov 21, 1999 5:22: 4 pm"
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
James Antill wrote:
>% alias abcd="echo abcd"
>% abcd () { echo xyz
>2> }
> /* running abcd at this point crashes zsh */
This is not a bug. It's a rather unintuitive, but standard, interaction
between aliases and functions. The word "abcd", when it is defined as
an alias, gets expanded anywhere that it appears in a command position.
The catch is that in the traditional function definition syntax, the name
of the function being defined is in command position. So the alias gets
expanded, and you end up doing
echo abcd () { echo xyz; }
The next catch is that this defines *both* "echo" and "abcd" as functions,
with the body you gave. "echo" is a function that calls itself.
When you run the "abcd" function, it calls the "echo" function, which
calls itself recursively until the stack overflows.
There are three ways to avoid this. Firstly, don't mix aliases and
functions, or at least define all functions before aliases. Secondly,
escape the command word when defining a function, to prevent it being
expanded as an alias. Finally, you can use the ksh function definition
syntax:
function abcd { echo xyz; }
which doesn't expand the function name as an alias.
-zefram
Messages sorted by:
Reverse Date,
Date,
Thread,
Author