|
|
Leopard: .bash_profile and .bashrc are not sourced when sudo su -?
|
|
|
|
Senior User
Join Date: Nov 2002
Location: US
Status:
Offline
|
|
Can anyone confirm .bash_profile/.bashrc are not sourced when sudo su - into the root account? Strangely there's no such problem for a normal user account. Thanks!
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
What is the difference between sudo su -, su, or su - root?
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2005
Status:
Offline
|
|
I don't use "sudo su". Are you typing "sudo su root" ?
The home directory for my root user ID (when I use "login root") is /var/root. Try putting any profile files there.
|
Mac Pro Quad: 2.66GHz; 4 GB Ram; 4x500GB drives; Radeon X1900, 23" Cinema Screen, APC UPS
PowerBook G4: 1.33GHz; 768MB Ram; 60GB drive
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Nov 2000
Location: in front of my Mac
Status:
Offline
|
|
.bash_profile gets sourced on login sessions, but not otherwise - that's where .bashrc comes in.
Try putting your .bash_profile in /var/root/ and using su. Then do a xterm and see if the .bashrc in /var/root/ gets sourced. Use echo commands to notify you of what is being sourced when.
|
•
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2002
Location: US
Status:
Offline
|
|
Originally Posted by Simon
.bash_profile gets sourced on login sessions, but not otherwise - that's where .bashrc comes in.
Try putting your .bash_profile in /var/root/ and using su. Then do a xterm and see if the .bashrc in /var/root/ gets sourced. Use echo commands to notify you of what is being sourced when.
My .bash_profile is indeed in /var/root, and by "su -" I should get a login session. I placed an echo inside .bash_profile and confirmed it's not sourced.
Weird thing is this same .bash_profile worked fine under Tiger, and it works fine with a non-root user in Leopard. Anything changed under the hood that I missed?
Thanks!
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Mar 2004
Status:
Offline
|
|
Originally Posted by fortepianissimo
My .bash_profile is indeed in /var/root, and by "su -" I should get a login session. I placed an echo inside .bash_profile and confirmed it's not sourced.
Weird thing is this same .bash_profile worked fine under Tiger, and it works fine with a non-root user in Leopard. Anything changed under the hood that I missed?
In /var/root, try .profile instead of .bash_profile
BTW, re: post #1... I'm lost:
If you have root, why are you using "sudo"?
What is the need? What is the ultimate goal?
|
-HI-
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2002
Location: US
Status:
Offline
|
|
Originally Posted by Hal Itosis
In /var/root, try .profile instead of .bash_profile
BTW, re: post #1... I'm lost:
If you have root, why are you using "sudo"?
What is the need? What is the ultimate goal?
Thanks - indeed .profile works. But "man bash" didn't mention this? Where is it described?
About the goal for doing sudo su -. It's just for me to occasionally fire off fink command or do some other system-wide installation etc.
Thanks!
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2005
Status:
Offline
|
|
Originally Posted by fortepianissimo
Thanks - indeed .profile works. But "man bash" didn't mention this? Where is it described?
Thanks!
At the moment, I'm on my G4 with OS 10.3.9, and ".profile" is in the man page. To find it, type this:
/\.profile
The first slash is for the find command, and the second is the prefix so the period isn't considered a wild card.
Here is what is says in 1.3.9:
When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
|
Mac Pro Quad: 2.66GHz; 4 GB Ram; 4x500GB drives; Radeon X1900, 23" Cinema Screen, APC UPS
PowerBook G4: 1.33GHz; 768MB Ram; 60GB drive
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
AFAIK,
su = switch user
su - username = switch user to that username and transfer current environment variables
sudo <command> = execute this command as root (requires you to be set as an admin in OS X)
sudo su = execute the switch user command as root, this is a little weird - you don't need to be root to switch users.
As for .profile vs .bash_profile, I've never really taken the time to understand this. It's a little bit unusual, and to add insult to injury for some reason my experiences always seem a little different on different Unix/Linux OSes... Maybe this is due to OS X Terminal environment variables? I'm not sure if iTerm would use these same variables...
I bet you could symlink .profile to .bash_profile and it would work fine...
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2002
Location: US
Status:
Offline
|
|
Originally Posted by rehoot
At the moment, I'm on my G4 with OS 10.3.9, and ".profile" is in the man page. To find it, type this:
/\.profile
The first slash is for the find command, and the second is the prefix so the period isn't considered a wild card.
Here is what is says in 1.3.9:
When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
Yes I did read that - but it didn't explain why it bypassed ~/.bash_profile for root, and only takes ~/.profile.
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2002
Location: US
Status:
Offline
|
|
Originally Posted by besson3c
AFAIK,
su = switch user
su - username = switch user to that username and transfer current environment variables
sudo <command> = execute this command as root (requires you to be set as an admin in OS X)
sudo su = execute the switch user command as root, this is a little weird - you don't need to be root to switch users.
As for .profile vs .bash_profile, I've never really taken the time to understand this. It's a little bit unusual, and to add insult to injury for some reason my experiences always seem a little different on different Unix/Linux OSes... Maybe this is due to OS X Terminal environment variables? I'm not sure if iTerm would use these same variables...
I bet you could symlink .profile to .bash_profile and it would work fine...
Indeed I ended up "ln -s .bash_profile .profile" and it works fine.
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2002
Location: US
Status:
Offline
|
|
An update and conclusion:
1. the shell for root is not bash, it's sh.
2. From man bash:
"If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|