cd function

Pete Gregory pete at wvus.wciu.edu
Sat Feb 16 14:11:36 AEST 1991


Hi, netters.  Here's a good one for you...

My login shell is /bin/sh (I guess I should say I'm running AT&T V.3.2,
actually Unisys PTX 1.1.1 for those who care), and I want my prompt
to include my current working directory.

I know how to do this in csh: alias cd 'chdir $1;set prompt="$cwd"' ,
but I can't figure it out in sh.

What I've tried:  putting a function called 'cd' in .profile:

cd()
{
   cd $*
   PS1="`pwd`"
}

...but alas this doesn't work because the shell uses its own internal cd
instead of running my function.  I've also tried a shell script called cd,
but this doesn't work for two reasons: 1) sh still uses its internal cd,
and 2) the shell's pwd changes, but not the parent, my login shell.

What I want to do is REPLACE sh's 'cd' with one of my own (but which still
uses sh's 'cd').  Well, what I REALLY want to do is get the prompt to
always show my current working directory (ie. `pwd`).

Any and all insights appreciated.
 
Pete Gregory, UNIX SA  |  pete at wvus.wciu.edu                  |
World Vision USA/ISD   |  wciu!wvus!pete                   ___|___
919 W. Huntingon Dr.   |  Voice: 818/357-7979 x3347           |
Monrovia, CA  91016    |  FAX:   818/303-6212                 |
                                                              |
Romanian orphans need our help!  Call 1-800-777-1229



More information about the Comp.unix.questions mailing list