Date: 17 Oct 1999 03:59:04 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: freebsd-questions@freebsd.org Subject: Re: bash's "\$" in PS1 doesn't work right Message-ID: <86ogdyn6p3.fsf@localhost.hell.gr> In-Reply-To: Arcady Genkin's message of "16 Oct 1999 13:23:27 -0400" References: <87g0zbxmdg.fsf@main.wgaf.net> <87aepjxlrk.fsf@main.wgaf.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Arcady Genkin <a.genkin@utoronto.ca> writes: > Arcady Genkin <a.genkin@utoronto.ca> writes: > > > I have the following in .bashrc: > > export PS1="\h:\w\$ " > > > > However, the "\$" doesn't result in "#" for root. I get the "$" sign. > > > "set" reports: > > PS1='\h:\w$ ' The reason is that bash tries to do variable substitution when you use double quotes, so the "\$ " thing means to bash: do not use the dollar sign for shell variable substitution, but use it as a single dollar sign. If you had used export PS1="\\h:\\w:\\\$ " it would have worked without a glitch, but this backslashing can end up in a true nightmare once you get to use nested expressions in the prompt, say the output of some command like `uname -r` somewhere in there. The solution is to use single quotes for anything that you don't care to have the shell substitute as a shell variable somewhere. Something like: export PS1='\h:\w\$ ' -- Giorgos Keramidas, <keramida@ceid.upatras.gr> "That field hath eyen, and the wood hath ears." [Geoffrey Chaucer, 1328-1400] 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?86ogdyn6p3.fsf>