Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!hal!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery) Newsgroups: comp.bugs.sys5 Subject: Re: ksh bug on function aliasing Message-ID: <1989Sep5.231422.11383@NCoast.ORG> Date: 5 Sep 89 23:14:22 GMT References: <776@tuminfo1.lan.informatik.tu-muenchen.dbp.de> Reply-To: allbery@ncoast.UUCP (Brandon S. Allbery) Followup-To: comp.bugs.sys5 Organization: North Coast Public Access UN*X, Cleveland, OH Lines: 34 As quoted from <776@tuminfo1.lan.informatik.tu-muenchen.dbp.de> by schmauss@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@NCoast.ORG uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu "Why do trans-atlantic transfers take so long?" "Electrons don't swim very fast." -john@minster.york.ac.uk and whh@PacBell.COM