ksh bug on function aliasing

Brandon S. Allbery allbery at NCoast.ORG
Wed Sep 6 09:14:22 AEST 1989


As quoted from <776 at tuminfo1.lan.informatik.tu-muenchen.dbp.de> by schmauss at lan.informatik.tu-muenchen.dbp.de (Oin):
+---------------
| Here is a bug I've found in ksh @(#)Version 06/03/86.
| I declared a function chdir() for the shell builtin cd and
| aliased cd to be chdir() ( see script below for details ).
| Now have a look at the following two different behaviours of ksh:
| 
| Situation 1:
|   declare function
|   declare alias
|   call alias
|   everything's fine...
| 
| Situation 2:
|   declare alias
|   declare function
|   call alias
|   @#$%%^&*
+---------------

This is not a bug; it's documented in the manual.  Since aliases is expanded
at the time that the function definition is read (*not* when it is executed!),
if the alias is defined first you end up with a recursive call.  (And your
"unalias cd" has no effect in *either* version except to blow away your
directory stack routine after the first call.)  If you define the function
first, "cd" isn't an alias when the function is read and the function is
constructed with the built-in "cd", which is what you want.

++Brandon
-- 
Brandon S. Allbery, moderator of comp.sources.misc	     allbery at NCoast.ORG
uunet!hal.cwru.edu!ncoast!allbery		    ncoast!allbery at hal.cwru.edu
"Why do trans-atlantic transfers take so long?"
"Electrons don't swim very fast."  -john at minster.york.ac.uk and whh at PacBell.COM



More information about the Comp.bugs.sys5 mailing list