On Wed, Sep 14, 2005 at 01:25:00PM +0200, Holly Bostick wrote:
> Charles Trois schreef:
> > Hello!
> > 
> > I am getting confused with profile, bashrc, etc. The prompt string I 
> > want to use is
> > 
> > PS1="[EMAIL PROTECTED] \W]\$ "
> > 
> > I therefore wrote it in /etc/profile (at two levels, root and 
> > non-root), ~/.bash_profile and ~/.bashrc.
> > 
> > If I log in as a plain user (moi), I get this:
> > 
> > [EMAIL PROTECTED] moi]$
> > 
> > which is all right. But, if I log in as root, I get the basic default
> > 
> > 
> > 
> > 
> > 
> > bash-2.05b# .
> > 
> > I thought that /etc/profile should provide the default, but I was 
> > obviously wrong. Trying to mend things, I created two files 
> > /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now,
> >  logging in as root, the result is
> > 
> > [EMAIL PROTECTED] root]$
> > 
> > which is wrong, since "$" appears in place of "#", as though my 
> > syntax of PS1 were incorrect, but I don't see that it is.
> 
> No, it's not incorrect, but if you wrote the exact same PS1 in the root
> entry as in the user entry, perhaps you see that there's a 'literal'
> dollar sign character at the end:
> 
> PS1="[EMAIL PROTECTED] \W]\$ "
> 
> which is going to be printed as itself, as you are not using any code to
> change it to the 'correct' character based on user (perhaps bash thinks
> you've escaped the closing bracket, not the following "$". A space
> between the bracket and the "\$" might solve this, but I've never really
> got /$ to work properly. It may, however, be because of the 'login shell
> issue' -- see below, but basically, if you're using su and not su -, your
> UID is not changing, so the /$ is not changing either).

No. That's wrong. 

[08:13 AM]wwong ~ $ id
uid=1001(wwong) gid=0(root) 
groups=0(root),6(disk),10(wheel),11(floppy),16(cron),18(audio),19(cdrom),27(video),35(games),245(locate),250(portage),408(web),440(speech),443(slocate)
[08:13 AM]wwong ~ $ su
Password: 
sep wwong # id
uid=0(root) gid=0(root) 
groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
sep wwong # 


<snip>

> So ~/.bashrc is king of the hill, as it is apparently meant to be, so
> we'll talk about that. As I said, the default ~/.bashrc contained a
> number of aliases, and because I use a lot of aliases, I worked with
> ~/.bashrc a lot (for both home and root). Using a lot of links (posted
> below) I was able to get a nice 3-line prompt that I like. I then copied
> the prompt to root's bashrc and made minor changes (the colors, mostly).
> and that was fine.
> 
> Then I tackled the problem of the login shell.
> 
> You see, ~/.bashrc is only sourced when you login (to the terminal,
> which, don't forget, is a virtual console). So if you're in the term as
> a user, and then you su normally to root, root's bashrc is not going to
> be sourced, and (among other issues) you're not going to get the right
> prompt (seemingly because your UID doesn't actively change to UID 0, but
> rather you remain the regular user with elevated permissions).

1. Your UID does change. See the experiment above. 
2. .bashrc is sourced for ALL interactive shells. .bash_profile is
sourced ONLY for login shells. So: opening an xterm sources .bashrc.
Logging in remotely via ssh sources .bash_profile. 
3. su opens an interactive shell. It DOES source .bashrc

> The solution to this is (for me, as I really like bash but am not all
> that good with it as yet, so any more 'elegant' solutions are unknown to
> me), is to make sure my su is always a login prompt (alias su="su -"),
> so that root's bashrc is sourced when I su, so I can use root's aliases,

4. "su -" would open a login shell, and thus source .bash_profile
instead of .bashrc

> and get root's $PATH, since there's nothing more annoying to me than
> su-ing to root and still getting a 'file not found' error because
> whatever I'm trying to do is still not in my $PATH, because root's PATH
> was somehow not exported by su-ing. I also added an ENV_SUPATH variable

I would say something is borked on your setup. Be default, su would
look in /etc/login.def for ENV_SUPATH and ENV_PATH for default PATHs
for superusers and users respectively. Here there's also a difference
between "su" and "su -". "su" loads ENV_SUPATH from /etc/login.def,
which by default is /sbin;/bin;/usr/sbin;/usr/bin. For "su -". because
it invokes a login shell, it should grab the path from /etc/profile,
which in turn grabs it from /etc/profile.env, which is created by
env-update from the information in /etc/env.d

-- 
I've got a patent pending on swallowing, oxidation, and chewing gum.
Sortir en Pantoufles: up 33 days, 15:15
-- 
[email protected] mailing list

Reply via email to