Date: Thu, 06 Jan 2000 18:51:24 -0800 From: R Joseph Wright <rjoseph@nwlink.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Bash prompt (Was: window manager question) Message-ID: <387554AC.C953BD4D@nwlink.com> References: <200001052224.XAA37273@dorifer.heim3.tu-clausthal.de> <387435D1.7E20347D@nwlink.com> <20000106175704.A7246@hades.hell.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
> > 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! I don't fully understand what you meant about shell variables, but it works. And that's the only line I need because it automatically checks for UID and acts accordingly. -- Best Regards, Joseph You will do foolish things, but do them with enthusiasm. Colette. 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?387554AC.C953BD4D>