Please explain PS1='\h:\w\$ '

Please explain PS1='\h:\w\$ '

Post by Donald Douglas Joll » Wed, 22 Feb 1995 04:31:53



I am using the slackware distribution of Linux distributed on CD-ROM
from Walnut Creek.  In the distribution that I have the /etc/profile
file contains the following line:

     PS1='\h:\w\$ '

OK.  I give up.  I don't get what this line is doing.  It's obviously
not doing what one would think, i.e., setting PS1 to \h:\w\$.  I was
able to accomplish what I wanted with the following snippit:

     if [ "$LOGNAME" = "root" ]; then
       PS1="# "
     else
       PS1="$ "
     fi

However, I'd like to understand what the PS1='\h:\w\$ ' line.  I'm
sure that there is a much easier way to accomplish what I want and
that the key is understanding this line.  Can anyone please help me
with this?

Thanks for any input.

     ... doug
______________________________________________________________________________
Doug Jolley           |    Don't bogart that file, my friend.    | PGP key

------------------------------------------------------------------------------

 
 
 

Please explain PS1='\h:\w\$ '

Post by Ruurd Pe » Wed, 22 Feb 1995 20:03:53



Quote:(Donald Douglas Jolley) writes:
>     PS1='\h:\w\$ '

>OK.  I give up.  I don't get what this line is doing.  It's obviously
>not doing what one would think, i.e., setting PS1 to \h:\w\$.  I was
>able to accomplish what I wanted with the following snippit:

>     if [ "$LOGNAME" = "root" ]; then
>       PS1="# "
>     else
>       PS1="$ "
>     fi

RTFM bash(1). Spoiler: export PS1='\$ ' accompishes what you are doing in
the above piece of code. To make you curious, here's mine for bash:

        if [ "`echo $TERM | cut -b1-3`" = "con" -o \
             "$TERM" = "xterm"   -o \
             "`echo $TERM | cut -b1-2`" = "vt" -o \
             "`echo $TERM | cut -b1-2`" = "vs" ]; then

        else

        fi
--
Grtz, RFP ;-)

 |o|     Ruurd Pels, Kamgras 187, 8935 EJ  Leeuwarden, The Netherlands   |o|
 |o| GC2.1 GAT/!/?/CS/B -d+(---) H s !g p? a w--(+++) v--(+++) C++ UL+++ |o|
 |o| P? L++ !3 E? N++ !V t+ !5 !j G?  tv- b++ D B? u++(---) h-- f? y++++ |o|

 
 
 

Please explain PS1='\h:\w\$ '

Post by Colin James Wyn » Wed, 22 Feb 1995 23:28:58



Quote:>      PS1='\h:\w\$ '
> OK.  I give up.  I don't get what this line is doing.  It's obviously
> not doing what one would think, i.e., setting PS1 to \h:\w\$.

Actually, it is doing exactly what you would think. :-)  PS1 is
treated by many shells as a special variable because people often want
to include special information which can not be completely determined
at run time.  Therefore, inside the definition for PS1 one uses escape
sequence to encode certain info to be evaluated whenever the prompt is
printed.  For example, bash (that is bash, isn't it?) converts \h to
be the hostname (not really necessary as an escape sequence, but more
convenient than including either $HOST or `hostname` or some such) and
\w evaluates to the present working directory.  Having once written
that prompt in ksh without escapes, I can assure you that getting the
right quoting can be a pain.  I imagine the \$ should evaluate to
exactly what you have in your if/then code:

Quote:>      if [ "$LOGNAME" = "root" ]; then
>        PS1="# "
>      else
>        PS1="$ "
>      fi

Check out the info page for bash.  All the escapes for PS1 should be
listed somewhere.

Hope this helps,

CJW

--
**********************************************************************
    /\       Colin J. Wynne             Washington and Lee University
   (())                                      Lexington, *ia

 /______\  
/________\ ``Every normal man must be tempted at times to
             spit upon his hands, hoist the black flag and
             begin slitting throats.''
                                                       --H. L. Mencken
**********************************************************************

 
 
 

Please explain PS1='\h:\w\$ '

Post by Daniel Barl » Wed, 01 Mar 1995 01:30:45




Quote:>However, I'd like to understand what the PS1='\h:\w\$ ' line.  I'm
>sure that there is a much easier way to accomplish what I want and
>that the key is understanding this line.  Can anyone please help me
>with this?

Try 'man bash' and/or the bash info file.

A brief explanation: \h prints the hostname, \w prints the working
directory, and \$ prints a # if root or a $ otherwise.  The prompt
you're looking for (deleted) could be set more succintly with

export PS1='\$ '

Daniel

--

``Our single posting of 6,000 was a drop in a huge bucket''
                                -- Canter & Siegel, to the Tenessee Bar

 
 
 

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. remove NGROUPS hard limit (resend)

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

4. How do I - Allow all Lowercase passwords

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

6. VW Smalltalk and PostregSQL

7. Please explain those field reported by 'free'

8. Partition problems!!!

9. Please explain 'run level'

10. ksh - please explain ':'

11. please explain DPMS settings in 'xset'

12. PS1 Line and the 'pwd' command

13. \$ in bash's PS1 doesn't do what it should