Bash prompt change

Mike Klinke lsomike at futzin.com
Tue Aug 3 03:36:01 UTC 2004


On Monday 02 August 2004 20:01, Mike Chambers wrote:
> Anyone notice/see their prompt change to [mike at scrappy ~]$ after
> the latest rawhide updates?  It seems to show the proper dir's when
> you switch out of home, but it shows ~ (yes I know that means your
> home dir) when you first change to a user and their home dir.
>
> --
> Mike Chambers
> Madisonville, KY
>
> "It's only funny until someone gets hurt...Then it's hilarious!"

After Bill answered I saw this in a "bash" FAQ at:

http://cnswww.cns.cwru.edu/~chet/bash/FAQ

---------
G5) How do I get the current directory into my prompt?

Bash provides a number of backslash-escape sequences which are 
expanded when the prompt string (PS1 or PS2) is displayed.  The full 
list is in the manual page.

The \w expansion gives the full pathname of the current directory, 
with a tilde (`~') substituted for the current value of $HOME.  The 
\W expansion gives the basename of the current directory.  To put the 
full pathname of the current directory into the path without any 
tilde subsitution, use $PWD.  Here are some examples:

	PS1='\w$ '	# current directory with tilde
	PS1='\W$ '	# basename of current directory
	PS1='$PWD$ '	# full pathname of current directory

The single quotes are important in the final example to prevent $PWD 
from being expanded when the assignment to PS1 is performed.
------------

Regards, Mike Klinke





More information about the test mailing list