Prompt as Current Directory?

Jay A. Konigsberg jak at sactoh0.UUCP
Sat Nov 18 13:11:57 AEST 1989


In article <Nov.16.00.56.12.1989.9985 at paul.rutgers.edu> 
broadman at paul.rutgers.edu (Alan Broadman) writes:
>
>I have a (hopefully) simple question. How can you get the UNIX prompt
>to always reflect the path to the current directory.

You can't change the ' cd ' command itself because it is a Bourne
shell built-in! However, the task can still be done. All that is
required is that the PS1 and PS2 variables are set in the current
shell layer.

The script shown is placed in my .profile and works fine. One word
of warning though, commands that give you a new shell, like newgrp,
will wipe it out till your next login. Also, get in the habit of
using "cdd" instead of "cd".


#### SHOULD BE THE LAST LINES IN THE .profile ####
# cdd - cd with a current directory in the prompt
echo "Enter: \" cdd = \" to return to a $ prompt"
cdd() {
if [ "$1" = "=" ]; then 
   PS1="$ "; PS2="> "
else
   cd $1
   PS1="`pwd` $ "; PS2="`pwd` > "
fi
}
cdd
-- 
-------------------------------------------------------------
Jay @ SAC-UNIX, Sacramento, Ca.   UUCP=...pacbell!sactoh0!jak



More information about the Comp.unix.questions mailing list