[net.bugs] Nasty shell bug

z (10/22/82)

There is a nasty bug which exists in the C shell and the Bourne shell,
and which probably exists in other shells as well.  I was teaching my
EMACS how to talk to the C shell, so that it could do the popular trick
of starting up a shell in a window.  One thing that it has to know is
what the shell's prompt is, so that it can deal with it in various
situations.  Simple, right?  All you have to is say "echo $prompt" (or
"echo $PS1" for the Bourne shell) and look at the output.  Wrong!!!!
The string you get back from these commands never has a trailing space,
even if the prompt really does (which is the usual case)!  I killed an
hour and a half tracking this thing down, until I did a "script" and
looked at the results.  I suppose this was put in way back when in order
to save the cpu time of outputting that final space.  Besides, "nobody's
going to see it, anyway".  Sigh.

	Steve Zimmerman
	decvax!cca!z
	z@cca

ark (10/23/82)

I do not know what the situation is for csh, but what you describe
is in fact the proper operation of the Bourne Shell.  Suppose you type
the following string at your terminal:  "echo a b c " (note the trailing
space).  The echo command gets three arguments: "a", "b", and "c", with
no trailing white space.  Thus, if you say "echo $PS1" and PS1 contains
"$ ", it is as if you had said "echo $ ": the echo command gets a $ as
its argument with no trailing space.  The way to do it is to say:

		echo "$PS1"

I have tried this and the output does indeed have the trailing space.

nrf (10/25/82)

The appropriate command to see your prompt is

	echo "$PS1"

N. R. Fildes, BTL Whippany

geo (10/26/82)

Surrounding things with a pair of " causes them to be treated
as a single argument in the Bourne Shell.  (I am not familiar
with the C-Shell.)  So if you were to use 
echo "$PS1"
rather than
echo $PS1
any trailing blanks would be preserved.

Geo Swan
Integrated Studies
University of Waterloo