Getting UNIX prompt to display current directory

Maarten Litmaath maart at cs.vu.nl
Tue Mar 21 12:16:53 AEST 1989


fristens at ncsugn.ncsu.edu (Brian Fristensky) writes:
\... it would involve getting pwd output into the shell variable
\$PS1, ...

It seems you're using /bin/sh (or ksh). The following will work:

	Solution 1 (put the following in a script `c').
	------------------------------
	#! /bin/sh
	#
	# c: a script to change the prompt of the parent to the new working
	# directory
	# to put in $HOME/.profile:
	#
	#    PARENT=$$
	#    export PARENT
	#    trap 'DIR=`cat $HOME/.dir`; cd $DIR; PS1="$DIR> "' 5

	cd $1
	pwd > $HOME/.dir
	exec kill -5 $PARENT
	------------------------------

	Solution 2 (if your sh has shell functions).
	------------------------------
	c()     # you might not be able to name this function `cd'
	{
		cd $1
+		PS1="`pwd`> "
	}
	------------------------------

	Solution 3 (if your sh has both shell functions and $PWD).
	------------------------------
	Change the line indicated with `+' to

		PS1="$PWD> "
-- 
 Modeless editors and strong typing:   |Maarten Litmaath @ VU Amsterdam:
   both for people with weak memories. |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list