Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: PS1 and the bourne shell... Message-ID: <6751@brl-smoke.ARPA> Date: Thu, 26-Nov-87 23:24:33 EST Article-I.D.: brl-smok.6751 Posted: Thu Nov 26 23:24:33 1987 Date-Received: Sun, 29-Nov-87 18:39:41 EST References: <279@caus-dp.UUCP> <1311@puff.wisc.edu> <137@anumb.UUCP> <9354@ufcsv.cis.ufl.EDU> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 37 Xref: mnetor comp.unix.questions:5118 comp.unix.wizards:5657 In article <9354@ufcsv.cis.ufl.EDU> esj@beach.cis.ufl.edu (Eric S. Johnson) writes: >The problem is that the (standard) bourne shell evaluates something >like PS1=$CWD or PS1=`pwd` once. At the point it encounters it. What >you need to do is modify it (bourne shell) to evaluate that variable >each time it uses it. Best-o-Luck. What garbage! If you want the time (or load average or ...) embedded in your prompt, then it would indeed want to be evaluated every time it is printed. However, since the only way to effect a change of current working directory in the shell is via the "cd" builtin, the prompt can be kept up to date with embedded CWD if some way can be found to make the "cd" command update $PS1. For the vanilla SVR2 Bourne shell, this is not possible (for "cd"), because builtins cannot be redefined. However, one could get in the habit of using some other shell function name such as "cwd" to change working directory, where "cwd" is defined as: cwd(){ if [ $# -lt 1 ] then cd else cd "$1" fi PS1=`pwd`'$ ' } If you have the "builtin" shell builtin, then you can name the above function "cd" and change the two occurrences of "cd" to "builtin cd". The "builtin" builtin is found in the 8th & 9th Edition UNIX and the BRL SVR2 Bourne shells. This is the approach we use in our fancy "myx"/630/BRL shell-based working environments. Very cozy. If you have a pre-SVR2 Bourne shell, then you probably don't have support for shell functions and you are indeed stuck, since chdir() done in a subshell (e.g. a shell script) will not affect the parent shell. (You could source the script, however, but that isn't as convenient as typing a 2- or 3-letter command name.)