Can you override root shell?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Can you override root shell?
# 1  
Old 06-23-2010
Can you override root shell?

Hi,

I'm trying to figure out the logic of my user shell and root shell Smilie
This might be best illustrated with an example.

If I log into the linux host I'm using and run the following:
Code:
-bash-3.2$ which python
/usr/local/bin/python

I now run sudo bash to become root and run the same command
Code:
bash-3.2# which python
/usr/bin/python

So roots path overrides the users path.

However, I thought that if I now run .bash_profile from the users directory:
Code:
bash-3.2# source .bash_profile

the users path would override the root path but apparently not as:
Code:
bash-3.2# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

bash-3.2# which python
/usr/bin/python

it still returns python from the root directory shell.
Is there any way to override this?
I know I should probably be running commands as:
sudo <command> etc but I'm confused as to the logic employed and I haven't been able to clear it up with google searches.

Can anyone outline the logic?

Last edited by pludi; 06-23-2010 at 08:03 AM.. Reason: code tags, please...
# 2  
Old 06-23-2010
You probably want to source /etc/profile, not /home/whatever/... but then it must've gotten sourced in the first place on login anyway.

Just being root doesn't make PATH behave differently as much as root gets a different PATH.

Code:
 # as root:
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2:/usr/qt/3/bin
# as user:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2:/usr/qt/3/bin:/usr/games/bin

Remember /etc/profile is a script, not dumb list, so may easily do different things depending on what user logs in. On my system there's a ROOTPATH variable in /etc/profile which is copied over PATH for the root user only.

Last edited by Corona688; 06-23-2010 at 11:36 AM..
# 3  
Old 06-24-2010
I've been told what the problem is. Thought i'd let you know.


If I check my .bash_profile, the path is setup as follows
Code:
PATH=$PATH:/usr/local/bin/:/usr/bin/:/usr/bin/jdk1.5.0_10/bin:/usr/sbin:$HOME/bin

This means that when I sudo to root my path is appended to roots.
What I should have is
Code:
PATH=/usr/local/bin/:/usr/bin/:/usr/bin/jdk1.5.0_10/bin:/usr/sbin:$HOME/bin




Thanks for the help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to override Classpath?

Hi, When I login to my HP-UX and fire the "set" command I see that the weblogic 9.2 classpath is already set. However, I wish to override the classpath to weblogic version 10.3 I have a script call setWLSEnv.sh that has the desired classpath. Thus, in my unix script i write .... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Solaris

Migration of system having UFS root FS with zones root to ZFS root FS

Hi All After downloading ZFS documentation from oracle site, I am able to successfully migrate UFS root FS without zones to ZFS root FS. But in case of UFS root file system with zones , I am successfully able to migrate global zone to zfs root file system but zone are still in UFS root file... (2 Replies)
Discussion started by: sb200
2 Replies

3. Web Development

override rw-r--r-- root/staff for .htaccess?

Hi, I get this question in the console when I try to delete a htaccess file. What does it mean ? override rw-r--r-- root/staff for .htaccess? thanks (2 Replies)
Discussion started by: aneuryzma
2 Replies

4. AIX

Can't login root account due to can't find root shell

Hi, yesterday, I changed root's shell in /etc/passwd, cause a mistake then I can not log in root account (can't find correct shell). I attempted to log in single-mode, however, it prompted for single-mode's password then I type root's password but still can not log in. I'm using AIX 5L version 5.2... (2 Replies)
Discussion started by: neikel
2 Replies

5. Programming

How to override my profile

I would like to override the default profile which is loaded when the system starts or When I run a program so that profile should get loaded in the settings. Is there any system call to do so. . (0 Replies)
Discussion started by: mobile01
0 Replies

6. Programming

override the function in C

hi , greetings , I have one doubt reg the C functions . I have a program sample.c , in which i have function name scanf , which reads a a variable and prints the variable inside the function . this scanf is nothing to do with C library function scanf , but i would like to use only user... (1 Reply)
Discussion started by: naren_chella
1 Replies

7. AIX

date override

When the aix date function is called by a routine, is the date function 'aware' of the name of the routine that is calling it, such that if we had the source code of the date function, we could modify it so that it provides a date to the caller depending upon the identity of the calling routine.... (1 Reply)
Discussion started by: gerry shacter
1 Replies

8. UNIX for Dummies Questions & Answers

root cron was override w/ 3rd party software

Hi Guys, I'm new in Unix Environment. Any Unix Guru around...I need help. My question is, is it possible that the root cron could be override with 3rd party software?How can it happen. Another thing, how the cron job works?, I mean how the Unix process the cron job , I don't have an idea... (2 Replies)
Discussion started by: kupal
2 Replies

9. IP Networking

Override

Hi My computer of late started misbehaving. Whenever I switch it on It say Override and then it takes long to boot. Surprising is that it opens excel automatic. What could be that? (1 Reply)
Discussion started by: Mulo
1 Replies

10. UNIX for Dummies Questions & Answers

Override protection.....

I am having this problem......when I run this script: print -n "Enter file name to be deleted: " read answer if then rm $name else echo "No such file with the name: $name exists" fi I was trying to test my script for errors, and basically when the user had files with the rights: 400,... (1 Reply)
Discussion started by: Makaveli.2003
1 Replies
Login or Register to Ask a Question