Prompt changing on the fly

wcs at ho95e.UUCP wcs at ho95e.UUCP
Tue Feb 3 09:43:56 AEST 1987


In article <2935 at diku.UUCP> storm at diku.UUCP writes:
>In article <432 at ethz.UUCP> wyle at ethz.UUCP (Mitchell Wyle) writes:
>>Does anyone out there have a shell script / program to change
>>the prompt DYNAMICALLY after each [CR]?
>
>You cannot use a shell script or a program to change the shell prompt
>dynamically, because the PS1/prompt variables are local to the shell,
>and therefore they can only be changed by the shell itself.  

If all you want to do is set the prompt based on a few variables (process id,
current directory, some-shell-variable, history-number), ksh and csh have some
hooks to do these.  I don't know csh, but I've seen people whose prompt
includes a number incremented by 1 each command; makes it easier to use csh's
boring version of history.

Ksh (which is upward-compatible with sh, and has decent history), allows you to
evaluate variables each time you access PS1.  Thus, my PS1 is set to
	PS1='e!!${PWD}> '
which looks like
	e!/usr/spool/news>
(the ! is doubled to prevent csh-like history-number substitution)
I don't think you can do execution at the prompt (which would be really slow),
but the newer versions of ksh let you set SECONDS to get a crude clock.
	SECONDS=0; export SECONDS
	PS1='Logged in $SECONDS: '
You can also set MAILPATH to check files other than just $MAIL.
-- 
# Bill Stewart, AT&T Bell Labs 2G-202, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs



More information about the Comp.unix.questions mailing list