`pwd` in Shell prompt

Don Shope des at uucsbb.UUCP
Mon Apr 4 12:33:01 AEST 1988


In article <12747 at brl-adm.ARPA> H235-017%IRLEARN.BITNET at cunyvm.cuny.edu (Mark Humphrys) writes:
>...
>I want to get the current directory to be automatically included in the Shell
>prompt.


The easiest way I have found of accomplishing this is by using a
Bourne shell "function". The function can be defined in your .profile.
Below is a sample fragment of my .profile. The function is called "c".
Use it exactly as you would use the "cd" shell command, with one 
addition: The syntax "c -" will switch back to the previous directory
that you were in. Have fun.

----------------- cut here ----------- .profile fragment ----------
export PS1 ODIR
ODIR=$HOME

# function to put current directory as part of prompt. It also
# "remembers" the previous directory, and goes there via "c -". This
# version also displays the system name as part of the prompt, which is
# useful in a networking environment.
c () 
  {
  if [ "$1" = "-" ]; then
     DIR=$ODIR
  else
     DIR=$1
  fi
  ODIR=`pwd`
  cd $DIR 
  PS1=`uuname -l`"!"`pwd`"> "
  }
c       # set the prompt now

------------------ end of cut -------------------------------------



More information about the Comp.unix.questions mailing list