zsh-workers
 help / color / mirror / code / Atom feed
* A couple of bugs in zsh-3.0.7
@ 1999-11-21 22:22 James Antill
  1999-11-21 22:41 ` Zefram
  0 siblings, 1 reply; 2+ messages in thread
From: James Antill @ 1999-11-21 22:22 UTC (permalink / raw)
  To: zsh-workers


 There are a couple of bugs in the way functions are handled in
zsh-3.0.7 ...

 It's easiest to show them...

% where abcd
% alias abcd="echo abcd"
% where abcd
echo abcd
% abcd
abcd
% abcd () { echo xyz  
2> }
% where abcd
echo abcd
abcd
 /* running abcd at this point crashes zsh */

 Where as...

% touch bin/abcd
% chmod +x bin/abcd
% where abcd
/home/james/bin/abcd
% abcd () { echo abcd
2> }
% where abcd
abcd
/home/james/bin/abcd
% abcd
abcd
% alias abcd="echo abcd"
% where abcd
echo abcd
abcd
/home/james/bin/abcd
% abcd
abcd

 Works ...

 Also...

% where ls
/bin/ls
/usr/bin/ls
% alias ls="echo abcd"
% where ls
echo abcd
/bin/ls
/usr/bin/ls
% ls () { echo xyz
2> }
% where ls
echo abcd
/bin/ls
/usr/bin/ls
% 
/* running abcd cores zsh at this point too */

-- 
James Antill -- james@and.org
I am always an optimist, but frankly there is no hope.
   -Hosni Mubarek


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: A couple of bugs in zsh-3.0.7
  1999-11-21 22:22 A couple of bugs in zsh-3.0.7 James Antill
@ 1999-11-21 22:41 ` Zefram
  0 siblings, 0 replies; 2+ messages in thread
From: Zefram @ 1999-11-21 22:41 UTC (permalink / raw)
  To: james; +Cc: zsh-workers

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-11-21 22:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-21 22:22 A couple of bugs in zsh-3.0.7 James Antill
1999-11-21 22:41 ` Zefram

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).