zsh-workers
 help / color / mirror / code / Atom feed
From: Zefram <zefram@fysh.org>
To: james@and.org
Cc: zsh-workers@sunsite.auc.dk
Subject: Re: A couple of bugs in zsh-3.0.7
Date: Sun, 21 Nov 1999 22:41:37 +0000 (GMT)	[thread overview]
Message-ID: <E11pffu-0005Fy-00@crucigera.fysh.org> (raw)
In-Reply-To: <nnr9hj5vub.fsf@code.and.org> from James Antill at "Nov 21, 1999  5:22: 4 pm"

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


      reply	other threads:[~1999-11-21 22:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-21 22:22 James Antill
1999-11-21 22:41 ` Zefram [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E11pffu-0005Fy-00@crucigera.fysh.org \
    --to=zefram@fysh.org \
    --cc=james@and.org \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).