From owner-freebsd-questions@FreeBSD.ORG Thu May 15 15:03:59 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2C7FA106564A for ; Thu, 15 May 2008 15:03:59 +0000 (UTC) (envelope-from gerard@seibercom.net) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.228]) by mx1.freebsd.org (Postfix) with ESMTP id CF94A8FC22 for ; Thu, 15 May 2008 15:03:58 +0000 (UTC) (envelope-from gerard@seibercom.net) Received: by wx-out-0506.google.com with SMTP id h27so311444wxd.7 for ; Thu, 15 May 2008 08:03:58 -0700 (PDT) Received: by 10.100.229.12 with SMTP id b12mr3158822anh.57.1210863837964; Thu, 15 May 2008 08:03:57 -0700 (PDT) Received: from scorpio ( [67.189.233.182]) by mx.google.com with ESMTPS id b3sm4858203ana.7.2008.05.15.08.03.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 15 May 2008 08:03:57 -0700 (PDT) Date: Thu, 15 May 2008 11:03:39 -0400 From: Gerard To: freebsd-questions@freebsd.org Message-ID: <20080515110339.297fa37e@scorpio> In-Reply-To: <482C4CC3.3080802@cs.okstate.edu> References: <1210810823.5782.1253224263@webmail.messagingengine.com> <482C4CC3.3080802@cs.okstate.edu> Organization: seibercom.net X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.9; i386-portbld-freebsd6.3) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEX+/v7++v6YOTrq8PCcuIX989UvOSj++v0BNCbpAAAAB3RJTUUHsQwfFzs7RBhzUQAAAhJJREFUOI1dU8GOqzAMNKIoV1bvwD1i0ysqrHplIdBrVSX7ATSbd03VVvn9tQNtQy0hjAdn7LED4AAcPtWm9RV+MPSfxhBLx9ajd6X/ngB6/mTwnRSZua7i7Ca+0ctZKo4Qmz+JY13X6I3nFZBxIYW1PbgfQ5RP8g0XlltEWGf3cV03joYpRnFbvYDKbXjZlXyyhEZA4lI+cN3NaVXE4VKjSwTExO10eTEkkJVqIAD5z0nUBQJluQDRSQjcrBiHAJxZlAH5CUMBMC7OcJ4LMQNnxhZ1HYPscMc6J4UlWRMNwzOpCcAHKSICd1EDn83abdREIbXsHkD1OinP1aCUCOEVRaa1lMcvywUWdYgk13JQUpYNKmvXQ8Kw5ML9YI5h8SakctBc7E/IYuLhYd/zZIk+1gM1vNweQBvHE0j+oYah3sMqAytQYlZk6+ANaaawJdu3OFzYGMZ3iGpa3qMlq9ZH0VZTgrCtw/ngdYkEIIpSbP1bWQAdFdX9vocBdkH2qVjVmuMu3gI5rjs814EUdrCZgWlPaxZZ3RiLFUtr+ud0PXwp2dnQSNXgePt6AZpBj6UMJ7VQkzN4utVeaSW1Dhn/kblGrKeMvNGnzwX4zuEDarYz1KdPtR60Gul0Gued+515SJXhCsl+Tx/3kY/UDvicPll9mfu50t3tvQ/thZpJYgeuwdSKNJ6tCD98MCgoxLDaPxbwqqwPWaWiAAAAAElFTkSuQmCC X-Face: "\j?x](l|]4p?-1Bf@!wN<&p=$.}^k-HgL}cJKbQZ3r#Ar]\%U(#6}'?<3s7%(%(gxJxxcR nSNPNr*/^~StawWU9KDJ-CT0k$f#@t2^K&BS_f|?ZV/.7Q X-Operating-System: FreeBSD-6.3 Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/.SLmKxQRLw3xq3JEWx104Rs"; protocol="application/pgp-signature"; micalg=PGP-SHA1 Subject: Re: Configuring Bash X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 May 2008 15:03:59 -0000 --Sig_/.SLmKxQRLw3xq3JEWx104Rs Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, 15 May 2008 09:46:27 -0500 Reid Linnemann wrote: > Written by Montag on 05/14/08 19:20>> > > This should be a fairly simple process, I don't really know what I > > am missing. > >=20 > > I've got the following in the .bash_profile of a basic user account: > >=20 > > # set prompt [user@host--/dir] $ (# for root) > > PS1 =3D ' [\u@\h--\w] '=20 > > case `id -u` in > > 0) PS1=3D'${PS1} # ';; # root > > *) PS1=3D'${PS1} $ ';; # everyone else > >=20 > > When I log in, I am greeted with: > > ${PS1} $ $ > >=20 > > However, if I su to root, I get: > > [root@host-- /home/user]#=20 > >=20 > > That is what I wanted, but for some reason it is not working for a > > normal user. I thought perhaps the problem could be > > that .bash_profile is only loaded when a non-login shell is > > spawned, but a quick consultation of man bash revealed that bash > > reads ~/.bash_profile when it is invoked as a login shell. =20 > >=20 > > My next thought was that it was a permissions issue, but: > > su > > chmod 777 .bash_profile > > exit > > logout > > login > >=20 > > That did not change the results, the output was still the same as > > above. This is all being done at the console, by the way. > >=20 > > Appreciate any advice, > >=20 > > montag > > -------------------------- > > "Give the people contests they win by remembering the words to more > > popular songs or the names of state capitals or how much corn Iowa > > grew last year. Cram them full of non-combustible data, chock them > > so damned full of 'facts' they feel stuffed, but absolutely > > 'brilliant' with information. Then they'll feel they're thinking, > > they'll get a sense of motion without moving." >=20 > There are a few problems with what you are attempting here. >=20 > Your ~/.bash_profile is executed once, only when you log in. When you > su to root, a shell is started for root (according to root's shell > set in /etc/passwd) and that shell will do whatever it wants to do as > far as dotfile processing is concerned. Your ordinary > user's .bash_profile is ignored. >=20 > Since the ordinary user's .bash_profile is only executed once, when > the user's shell starts, the *) condition is always met in the case > statement, so that expression is executed: >=20 > PS1=3D'${PS1} $ ';; >=20 > This will always result in PS1 being the literal '${PS1} $ ' for that > user. Why? Because if you read your bash manual you'll see that > variable expansion does not happen in single quoted strings. >=20 > PS1=3D"${PS1} \$ ";; >=20 > The above string will do what you intend, it will set PS1 to whatever > ${PS1} is expanded to, plus the extra ' $ ' (you have to escape a > literal $ in a double quoted string). >=20 > As has been mentioned before, what you really want is to use the '\$' > literal to clue in the sh/bash to use a # for root and $ for all other > users. >=20 > PS1=3D"${PS1} \\$ ";; >=20 > That is the PS1 that will do it. >=20 > But again, because su invokes a new shell, if root's shell is not a sh > variant that uses $PS1, like the default csh, your prompt will not > carry over. csh will uses its own internal prompt variable and ignore > sh's PS1 environment variable. I placed the following in my ~/.bash_profile file. # This is the .bash_profile file # Read on bash login and similar to .profile # This file passes control to the '.bashrc' file if it is present if [ -f ~/.bashrc ]; then . ~/.bashrc fi Then in my ~/.bashrc file, I created an alias: alias su=3D'su -m' Now, whenever I go to root, the environment is not modified and I still have bash as my shell. I don't know if this will work for you or not. It should not hurt to try it. --=20 =E2=80=9CGerard=E2=80=9D gerard@seibercom.net Love is in the offing. Be affectionate to one who adores you. --Sig_/.SLmKxQRLw3xq3JEWx104Rs Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkgsUNYACgkQ6DWTaTcTwMl4RQCfeyjnr9GxXkwHyNhdoS77gcwA c88An20aeCBinB7JQB9mRBmwqcmIpiMF =E/UL -----END PGP SIGNATURE----- --Sig_/.SLmKxQRLw3xq3JEWx104Rs--