Thread View: comp.bugs.sys5
3 messages
3 total messages
Started by Oin
Mon, 04 Sep 1989 10:58
ksh bug on function aliasing
Author: Oin
Date: Mon, 04 Sep 1989 10:58
Date: Mon, 04 Sep 1989 10:58
72 lines
2284 bytes
2284 bytes
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...
305 $ chdir ()
>>> {
>>> unalias cd
>>> cd $*
>>> PS1="${PWD} ! \$ "
>>> alias cd=chdir
>>> }
306 $ alias cd=chdir
307 $ cd /tmp
/tmp 308 $ cd /usr/include
/usr/include 309 $ type cd
cd is an alias for chdir
/usr/include 310 $ type chdir
chdir is a function
/usr/include 311 $ typeset -f chdir
function chdir
{
unalias cd
cd $*
PS1="${PWD} ! \$ "
alias cd=chdir
}
Situation 2:
declare alias
declare function
call alias
@#$%%^&*
/usr/include 312 $ chdir ()
>>> {
>>> unalias cd
>>> cd $*
>>> PS1="${PWD} ! \$ "
>>> PS2="${PWD} >>> "
>>> alias cd=chdir
>>> }
/usr/include 313 $ type cd
cd is an alias for chdir
/usr/include 314 $ type chdir
chdir is a function
/usr/include 315 $ typeset -f chdir
function chdir
{
unalias cd
cd $*
PS1="${PWD} ! \$ "
PS2="${PWD} >>> "
alias cd=chdir
}
/usr/include 316 $ cd /
sh: chdir: recursive call
Franz "Oin" Schmausser local: lan.informatik.tu-muenchen.dbp.de
TU Muenchen, Inst. f. Informatik DFN: schmauss@{local}
Arcisstrasse UUCP: schmauss%{local}@unido.uucp
D-8000 Muenchen ARPA/CS: schmauss%{local}@relay.cs.net
Re: ksh bug on function aliasing
Author: Brandon S. Allbery
Date: Tue, 05 Sep 1989 23:14
Date: Tue, 05 Sep 1989 23:14
34 lines
1905 bytes
1905 bytes
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
Re: ksh bug on function aliasing
Author: scott.thompson
Date: Wed, 06 Sep 1989 17:19
Date: Wed, 06 Sep 1989 17:19
28 lines
1493 bytes
1493 bytes
From article <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:
>
... example deleted ...
>
This is not a bug, as a matter of fact it is documented; aliases are
expanded at the time of function DEFINITION.
By the way ksh will expand the $PWD environment variable in PS1
automagically, no need for the function. I believe this is supported in
the version you are using, just postpone the evaluation of the
appropriate variable, namely $PWD:
PS1="\${PWD} ! \$ "
PS2="\${PWD} >>> "
Also, you don't need to unalias cd within the chdir function, just place
it in single quotes. ie:
'cd' $*
--
Scott Thompson (IH 6W-207), AT&T Bell Labs, Naperville, Il. 60566
VOICE: (312)-979-2237 UUCP: ...!att!ihlpa!sft
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads