Gentoo Archives: gentoo-user

From: Willie Wong <wwong@×××××××××.EDU>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Bash prompt
Date: Wed, 14 Sep 2005 12:46:05
Message-Id: 20050914124111.GA24549@princeton.edu
In Reply to: Re: [gentoo-user] Bash prompt by Hans-Werner Hilse
1 On Wed, Sep 14, 2005 at 11:30:19AM +0200, Hans-Werner Hilse wrote:
2 > Hi,
3 >
4 > On Wed, 14 Sep 2005 11:15:13 +0200
5 > Charles Trois <charles.trois@×××××××.fr> wrote:
6 >
7 > > I am getting confused with profile, bashrc, etc.
8 > > The prompt string I want to use is
9 > >
10 > > PS1="[\u@\h \W]\$ "
11 > >
12 > > [...]
13 > > I thought that /etc/profile should provide the default, but I was
14 > > obviously wrong. Trying to mend things, I created two files
15 > > /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now,
16 > > logging in as root, the result is
17 > >
18 > > [root@sirrah root]$
19 > >
20 > > which is wrong, since "$" appears in place of "#", as though my syntax
21 > > of PS1 were incorrect, but I don't see that it is.
22 >
23 > That's probably due to multi level backslash escaping. Because you
24 > surrounded the prompt string with "", the backslash isn't surviving the
25 > first parser run by bash. You'd need to double it or even triple it
26 > (because the "$" may need escaping on the first level, too).
27
28 Use single quotes if you want to use \$
29 $ is a reserved character in bash. So when using double quotes, you
30 need to type \\$
31
32 sep wwong # export PS1="[test]\$ "
33 [test]$ export PS1="[test]\\$ "
34 [test]# export PS1='[test]\\$ '
35 [test]$ export PS1='[test]\$ '
36 [test]#
37
38 W
39 --
40 "Dude, this is making the same approximation twice in a row. It's like a
41 whack-a-mole game."
42 ~DeathMech, Some Student. P-town PHY 205
43 Sortir en Pantoufles: up 33 days, 15:41
44 --
45 gentoo-user@g.o mailing list