LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-01-2007, 05:06 PM   #1
usafitz
Member
 
Registered: Feb 2004
Location: Albuquerque
Distribution: Fedora 9
Posts: 46

Rep: Reputation: 15
what is going on with $PATH ??


I have asked about this topic before but haven't really gotten a grasp of it, so I'm asking for more help if possible.

bottom line is I want to be able to run 'ifconfig' and other commands like it as my user (instead of root)... but I can't unless I'm logged in as root. It won't even work if I'm logged in as my user and su over to root. Prior posts said I needed to change the PATH for my user. Here's what I have:

[user1@localhost ~]$ $PATH
bash: /usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/user1/bin: No such file or directory
[user1@localhost ~]$ su
Password:
[root@localhost user1]# $PATH
bash: /usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/user1/bin: No such file or directory

Since they look basically the same, what the heck is going on? Do I need to add a path or what? Thanks for the help.
 
Old 12-01-2007, 05:23 PM   #2
rupertwh
Member
 
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 297

Rep: Reputation: 49
Use
Code:
su -
instead (man su) to get root's environment.

(And btw: with '$PATH' you tried to execute your path rather than display it. Use 'echo $PATH' to display it -- or any other variable).
 
Old 12-01-2007, 05:31 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
"su" means take on root powers
"su -" means to ALSO switch to root's environment, including $PATH.
Thus is is puzzling to see ANY difference.

To modify (anyone's) PATH, do this: export PATH="$PATH:<newpathname>"

eg, to add /sbin:
export PATH="$PATH:/sbin"
To make the entry permanent, you have to modify one of the startup scripts. Which one depends on the distro.
 
Old 12-01-2007, 05:32 PM   #4
usafitz
Member
 
Registered: Feb 2004
Location: Albuquerque
Distribution: Fedora 9
Posts: 46

Original Poster
Rep: Reputation: 15
cool, thanks rupertwh, that solved half of the conundrum. How can I add the same path to user so that I can execute that command as user instead of having to switch to root every time? (or is that not a smart idea?)
 
Old 12-01-2007, 05:48 PM   #5
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,877

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
Quote:
How can I add the same path to user so that I can execute that command as user instead of having to switch to root every time?
pixellany wrote
Quote:
To modify (anyone's) PATH, do this: export PATH="$PATH:<newpathname>"

eg, to add /sbin:
export PATH="$PATH:/sbin"
To make the entry permanent, you have to modify one of the startup scripts. Which one depends on the distro.
What hasn't been said is that you can run the command from anywhere in the directory tree, if you enter the full path to the executable: example: /sbin/ifconf.
Also not mentioned is the matter of permission: if the user doesn't have permission to execute, it won't matter how you enter the command.

Last edited by bigrigdriver; 12-01-2007 at 05:51 PM.
 
Old 12-01-2007, 06:16 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Use sudo and include the path in the command.
sudo /sbin/ifconfig

If you want to just list the information as in the above command, then you don't need to run the command as root, and don't need sudo. If you want to set the IP address or gateway address of an interface than you need to do that as root.
 
Old 12-01-2007, 06:20 PM   #7
usafitz
Member
 
Registered: Feb 2004
Location: Albuquerque
Distribution: Fedora 9
Posts: 46

Original Poster
Rep: Reputation: 15
Awesome! That was spot on... thanks again for the responses. Time to play as user instead of root... thank goodness!
 
Old 12-01-2007, 08:11 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Actually, su means to switch user, (by default to root if you are non-root), but you can switch to any user from root if you want to test their env.
As mentioned, use the '-' empty switch to get the tgt user's env, otherwise you keep your env.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
export Path=/usr/java:$Path does not seem to work lumix Linux - Newbie 1 03-19-2007 04:11 PM
Do you add to the path line or make a new path in /etc/profile? M$ISBS Linux - Newbie 2 12-13-2006 03:14 PM
Image Path reference in Linux (Absolute path) javabuddy Linux - General 7 06-05-2006 08:45 AM
script to change unix path to windows path in all files csross Programming 8 04-29-2006 02:05 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 07:10 PM


All times are GMT -5. The time now is 08:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration