Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Jan 2000 17:57:04 +0200
From:      Giorgos Keramidas <charon@hades.hell.gr>
To:        R Joseph Wright <rjoseph@nwlink.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Bash prompt (Was: window manager question)
Message-ID:  <20000106175704.A7246@hades.hell.gr>
In-Reply-To: <387435D1.7E20347D@nwlink.com>
References:  <200001052224.XAA37273@dorifer.heim3.tu-clausthal.de> <387435D1.7E20347D@nwlink.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jan 05, 2000 at 10:27:30PM -0800, R Joseph Wright wrote:

> There is only one problem.  My .rc files have this setup, as you
> described, but modified for bash:
> 
> if [[ $EUID -eq 0 ]]; then
> 	PS1="root@\h\w\$"
> else
> 	PS1="joseph@\h\w\$"
> fi
> According to the man page on bash, the "$" is supposed to show up as "#"
> if uid is 0, otherwise it will show as "$".  It doesn't do this,
> however.  It always shows up as "$", regardless of uid.

Actually, when you use "\$" enclosed in double quotes, as shown above,
then bash will try and expand shell variables in the string.  The dollar
sign is used to start shell variable substitutions.  This would make a
prompt like "($UID) " work fine, replacing $UID with the current UID.
However, using a backslash, you can escape a `$' character, and force
bash to insert a literal `$' in that place (always speaking of double
quotes, here).

If you don't want shell-variable substitution in the prompt value (which
happens at the time the PS1 value is evaluated, *before* it gets
assigned to PS1), then you are better off using single quotes.  Try:

	PS1='\u@\h:\w\$ '	# note the single quotes!


Ciao.

-- 
Giorgos Keramidas, < keramida @ ceid . upatras . gr >
"What we have to learn to do, we learn by doing." [Aristotle]


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000106175704.A7246>