UNIX prompts (-ksh)

Badger BA 64810 bbadger at x102c.harris-atd.com
Tue Mar 28 03:29:56 AEST 1989


In article <4549 at vpk4.UUCP> hjespers at attcan.UUCP (Hans Jespersen) writes:
>In article <2391 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>>In article <11080 at well.UUCP> tneff at well.UUCP (Tom Neff) writes:
>>>Actually not even the classic Korn shell solution of
>>>
>>>	export PS1='$PWD> '
>>>
>>>seems to work everywhere.  
> 
>>I don't know ksh, but all the other shells I've seen use single-quotes
>>to protect against variable substitution...
>
>Absolutely correct. I think Tom ment
>
>	export PS1=`$PWD> `
>	           ^      ^
[.signature deleted]

The original is correct:
>>>	export PS1='$PWD> '
Note single quotes:^      ^
The ``correction'' is incorrect:
>       export PS1=`$PWD> `
Note back-quotes:  ^      ^

The reason for using single quotes is to prevent the shell from evaluating 
$PWD at the time of defining exported variable PS1.  What *should* happen 
then is that the string value of PS1 is subject to parameter substitution 
*at the time the prompt is printed*.  In that case the *current* value of
PWD can be substituted.  I gather from your experience that not all 
implementations of ksh work the same way.  Perhaps another variable must be 
set to trigger evaluation of the prompt?  This is sometimes done to retain 
compatibility with older shell scripts.  If the ``special variable'' is not
set, then the older compatible features are used.  (I'm not saying it *is* so,
just that this is a possibility.  Versions of csh I've used have this feature
for 'lineeditmode' and 'filec', for instance.)

The documentation I have for ksh variable PS1 states:

	PS1	The value of this parameter is expanded for parameter
		substitution to define the primary promt string which 
		by default is ``$''.  The character ! in the primary 
		prompt string is replaced by the *command* number (See
		Command Re-entry below).

There doesn't seem to be any doubt here that 
	export PS1='$PWD> ' 
should execute correctly, giving the present working directory set by the
cd command.

Maybe you have an impoverished version of ksh?  Maybe you're really running sh?

I seem to have the same problem with the 'tcsh' I'm running, none of the 
recently posted strings such as:
	set prompt="%m: (%h)"
have worked for me.  I just get the literal string.  My tcsh does do 
command line editing, file name completion and inline history completion, 
but the prompt string doesn't seem to do any prompt-time substitutions.

By the way, in .cshrc I use this:
if (! $?prompt) exit	#not an interactive subshell?
set     prompt_="`uname -n`>"
set     prompt="`tput smso`${prompt_}`tput rmso` "
if ($?WINDOW_ME || $?DISPLAY ) then
  set ti_ts="`tput ts`"	#to status line
  set ti_fs="`tput fs`"	#return from status line
  alias	titl 'echo -n ${ti_ts}${prompt_}": `dirs`"${ti_fs}'	#delayed vars
endif

Of course this could be done more simply as:
set     prompt="`tput smso;uname -n;echo '>';tput rmso` "
alias	titl 'echo -n "`tput ts;uname -n; echo -n :;dirs;tput fs`"'
but I think the variable substitution method above is faster to execute.

This solves some of the problems with terminal-dependent code, by using SYS V's
tput command.  ``tput'' is a simple program, but I haven't seen it ported to 
BSD/termcap.  Anyone out there know if this has been done?  


Bernard A. Badger Jr.	407/984-6385          |``Use the Source, Luke!''
Secure Computer Products                      |``Get a LIFE!''  -- J.H. Conway
Harris GISD, Melbourne, FL  32902             |Buddy, can you paradigm?
Internet: bbadger%x102c at trantor.harris-atd.com|'s/./&&/' Tom sed expansively.



More information about the Comp.unix.questions mailing list