You are not logged in.

#1 2009-05-04 16:00:41

aqamar
Member
Registered: 2008-09-01
Posts: 49

[ SOLVED ] a little issue with the command su

Hi, sometimes when a type su and insert the root password, in the shell appears bash-3.2#; other times appears root@galahad and this is ok.

Only is when a type su, with su - always appears my root@galahad in my shell.

What is wrong with the command su?

Greetings

Last edited by aqamar (2009-05-05 03:05:28)

Offline

#2 2009-05-04 16:25:03

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [ SOLVED ] a little issue with the command su

man su
man bash

running `su -` makes it a login shell which --i believe-- affects what files are sourced and can therefore affect the variable $PS1 which determines your prompt; running just `su` is not a login shell and that must mean whatever file defines your root's $PS1 is not being sourced.  hence the bash fallback prompt.

me, in both my ~/ and root's home /root/ i have a .bash_profile which sources a .bashrc which defines a PS1 string.  i get the correct PS1 with `su` or `su -`

i hope all that made sense.  smile

┌─[ 12:23 ][ blue:~ ]
└─> cat .bash_profile
. $HOME/.bashrc

┌─[ 12:23 ][ blue:~ ]
└─> grep ^PS1 .bashrc
PS1="\[$B\]┌─\[$W\][ \[$Y\]\A \[$W\]][ \[$G\]\h:\w \[$W\]]\n\[$B\]└─\[$Y\]> \[$W\]"

┌─[ 12:24 ][ blue:~ ]
└─> su
Password:

[ blue /home/patrick ] > exit
exit

┌─[ 12:24 ][ blue:~ ]
└─> su -
Password:

[ blue ~ ] > cat .bash_profile
. $HOME/.bashrc

[ blue ~ ] > grep ^PS1 .bashrc
PS1="[ \[$R\]\h \w\[$W\] ] > "

[ blue ~ ] > see the difference?

edit: i really should use Preview before Submit sometimes.

Last edited by brisbin33 (2009-05-05 13:25:26)

Offline

#3 2009-05-04 16:34:50

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [ SOLVED ] a little issue with the command su

I can confirm the 'issue', but I don't know where one should look to fix it. The thing is, a regular su will give you root permissions but not the PATH values of the root user (and other environment variables). Su - will give you a 'full' root session, and also its prompt.

Edit: #8 from this topic may provide the answer, but I'm at work, so I can't check smile.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#4 2009-05-04 22:22:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,223
Website

Re: [ SOLVED ] a little issue with the command su

brisbin33 wrote:

running `su -` makes it a login shell which --i believe-- affects what files are sourced and can therefore affect the variable $PS1 which determines your prompt; running just `su` is not a login shell and that must mean whatever file defines your root's $PS1 is not being sourced.  hence the bash fallback prompt.

Correct.

Offline

#5 2009-05-04 22:59:20

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [ SOLVED ] a little issue with the command su

B wrote:

I can confirm the 'issue', but I don't know where one should look to fix it. The thing is, a regular su will give you root permissions but not the PATH values of the root user (and other environment variables). Su - will give you a 'full' root session, and also its prompt.

Edit: #8 from this topic may provide the answer, but I'm at work, so I can't check smile.

i get the correct prompt with both 'su' and 'su -' by simply having /.bash_profile -> /.bashrc in _both_ my ~/ and /root/ if that's the behavior you want, that's the way to do it.  the 'difference' i was showing in the second part of my earlier post was simply that 'su -' moves root into his home (/root/) while 'su' keeps him in the cwd (/home/patrick/).  the prompt works either way though.

Offline

#6 2009-05-05 03:04:39

aqamar
Member
Registered: 2008-09-01
Posts: 49

Re: [ SOLVED ] a little issue with the command su

@brisbin33: thanks a lot, i copy all my ~/.bash* to /root/ and now always show "root@myhost"; who knows why sometimes show "bash-3.2" and othertimes "root@myhost"... BTW: your PS1 rocks!!! wink


sometimes have a feel of  hate/love to archlinux, because is helping me to learn and dont be lazy

Offline

Board footer

Powered by FluxBB