ksh... PS1=$$ PS1="$$" PS1='$$'... aargh...

ksh... PS1=$$ PS1="$$" PS1='$$'... aargh...

Post by David Feldm » Fri, 18 Feb 1994 08:29:08



I realize $$ is ksh-ish for current PID. The question is when does $$ get mapped
to the current PID? Why does PS1='$$' leave me with my prompt as the current
PID? Can the prompt be made into $$ by other contortions? Thanx!
 
 
 

ksh... PS1=$$ PS1="$$" PS1='$$'... aargh...

Post by David Rybo » Fri, 18 Feb 1994 09:06:54


|I realize $$ is ksh-ish for current PID. The question is when does $$ get mapped
|to the current PID? Why does PS1='$$' leave me with my prompt as the current
|PID? Can the prompt be made into $$ by other contortions? Thanx!

I believe this will work:

PS1=\$\$

Dave.

 
 
 

ksh... PS1=$$ PS1="$$" PS1='$$'... aargh...

Post by David W. Tamk » Fri, 18 Feb 1994 15:04:12


(It's a regular Davidfest here.  Our parents must all have read the same baby
 name books.)



F> I realize $$ is ksh-ish for current PID. The question is when does $$ get
F> mapped to the current PID? Why does PS1='$$' leave me with my prompt as
F> the current PID? Can the prompt be made into $$ by other contortions?
F>  Thanx!

R> I believe this will work:
R> PS1=\$\$

I believe Mr. Rybolt has erred.

PS1 is scanned once when it's defined and again when the prompt is displayed,
so PS1="$$" or PS1=$$ will use the PID as of when ksh is invoked and PS1='$$'
or PS1=\$\$ (or, same result, PS1=\$$) will both use the PID as of when the
prompt is displayed (which will turn out to be the same, I suppose, unlike
"$PWD" vs. '$PWD', which will differ as soon as you cd out of the directory
where you were when you invoked that particular shell).  That's certainly
what happens for me.

Think of it this way: if you say PS1="$$" you store the PID in PS1.  If you
say PS1='$$' you store two dollar signs in PS1.  But when the prompt is
displayed, you don't get `echo $PS1` but rather `eval echo $PS1`, and
`eval echo '$$'` is the same as `echo $$` and returns the PID.

Mr. Feldman will have to use PS1='\$$' or PS1=\\$\$ or PS1=\\\$$ if he wants
two literal dollar signs in his prompt.

David W. Tamkin  P. O. Box 3284  Skokie IL  60076-6284

 
 
 

ksh... PS1=$$ PS1="$$" PS1='$$'... aargh...

Post by David Rybo » Fri, 18 Feb 1994 15:56:48



Quote:(David) writes:
(David) writes:

|I believe Mr. Rybolt has erred.

That is correct...
I mistakenly assumed that the Bourne Shell's environment was
closely equivalent to ksh.

PS1='$$'
works fine in the Bourne shell...
but
PS1='\$$'
must be used in the Korn shell as David ( :-) ) points out.

|PS1 is scanned once when it's defined and again when the prompt is displayed,
|so PS1="$$" or PS1=$$ will use the PID as of when ksh is invoked and PS1='$$'
|or PS1=\$\$ (or, same result, PS1=\$$) will both use the PID as of when the
|prompt is displayed (which will turn out to be the same, I suppose, unlike
|"$PWD" vs. '$PWD', which will differ as soon as you cd out of the directory
|where you were when you invoked that particular shell).  That's certainly
|what happens for me.

|Think of it this way: if you say PS1="$$" you store the PID in PS1.  If you
|say PS1='$$' you store two dollar signs in PS1.  But when the prompt is
|displayed, you don't get `echo $PS1` but rather `eval echo $PS1`, and
|`eval echo '$$'` is the same as `echo $$` and returns the PID.

|Mr. Feldman will have to use PS1='\$$' or PS1=\\$\$ or PS1=\\\$$ if he wants
|two literal dollar signs in his prompt.

|David W. Tamkin  P. O. Box 3284  Skokie IL  60076-6284

 
 
 

1. How to translate Linux's PS1 prompt to Unix's PS1 prompt?

Hi all,

I tried to write a script  that can display the prompt as Linux does for
example:


#
or

$

Here is my script (It works on ksh of UnixWare 7)

UID=`id -u`
if [ $UID -eq 0 ]; then

# '
else

$ '
fi

but It will not display properly after running the command 'priv' to become
another users.

I wonder if I can do a script that can display the prompt as Linux prompt on
almost Unix system in Bourne Shell or Korn Shell without to install Bash.

 Thanks in advance for any advise.

H.V

2. NIS client can't find NIS server

3. PS1='[$PWD]'; how can I reduce the length of PS1 when it is long?

4. Anyone have user quotas set up for linux 1.2.13?

5. How to translate Linux's PS1 prompt to Unix's PS1 prompt?

6. Smart vs Applix Office applications

7. KSH: How to change PS1 while running "su"?

8. An Absolute Newbie to the Alpha World

9. ksh: $PWD in $PS1 doesn't change with directories

10. Where to put "PS1=" for root?

11. What really happens w/ PS1="! " ?

12. How To: set PS1 to show users "current" directory?

13. PS1 Line and the 'pwd' command