Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!choreo!chris From: chris@choreo.COM.COM (Chris Hare / System Manager) Newsgroups: comp.unix.wizards Subject: RE: PWD in Bourne Shell PS1 Message-ID: <18@choreo.COM> Date: 6 Jan 90 19:40:49 GMT References: <21894@adm.BRL.MIL> <8790.259b3142@ecs.umass.edu> Reply-To: chris@choreo.UUCP (Chris Hare / System Manager) Followup-To: As Above Organization: Choreo Systems Inc., Ottawa, Canada Lines: 41 In article <8790.259b3142@ecs.umass.edu> Satam writes, > Inserting the following three aliases will help achieve the same > effect. Note that this is only for csh. > ------------------------------------------------------------ > alias cd 'chdir \!* && set prompt="${cwd:t}_\\!% "' > alias pushd 'pushd \!* && set prompt="${cwd:t}_\\!% "' > alias popd 'popd \!* && set prompt="${cwd:t}_\\!% "' > ------------------------------------------------------------- This is quite true. However, a similar thing can be implemented in the Bourne shell using shell functions. There are however two caveats : 1. We cannot use the name of a built in shell command 2. We must recaculate the PS1 each time we do a cd. Firstly, becase we want the PS1 to be updated whenever we change directories, we cannot use the builtin 'cd' command, but something like it. We must also remember to use the new command, because using a cd will mean that the directory reflected in our PS1 will be incorrect. You can try this Bourne shell function : go() { if [ "$1" ] # if we got an argument then cd $1 else # otherwise go home cd $HOME fi PS1=`pwd`"> " # change the PS1 } Remember, shell functions are not passed to their subshells. Chris Hare Choreo Systems Inc. Coordinator, Systems Management 150 Laurier Ave West Authorized SCO Instructor Ottawa, Canada Phone 613-238-1050 Fax 613-238-4453 *** It Works for ME ! *** email : uunet!choreo!chris