LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   editing PATH in bash profile (https://www.linuxquestions.org/questions/linux-newbie-8/editing-path-in-bash-profile-643725/)

kaiwan 05-21-2008 04:24 AM

editing PATH in bash profile
 
Hi!
I have installed Fedora 9.
When I try to run some command, like fdisk I get following error:
Code:

[miroslav@localhost ~]$ fdisk
bash: fdisk: command not found
[miroslav@localhost ~]$ sudo fdisk
sudo: fdisk: command not found

So I edited my bash profile to add /sbin and /usr/sbin to PATH,
and it looks lite this now:
Code:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:/usr/sbin:/sbin:$HOME/bin

export PATH
unset USERNAME

And still I cant run fdisk, only way to run it is like this:
Code:

sudo /sbin/fdisk
Does not work after log out or reboot.

Nathanael 05-21-2008 04:43 AM

what does
Code:

sudo -s
echo $PATH

give you?

note: sudo echo $PATH is not the same!

kaiwan 05-21-2008 04:54 AM

Quote:

Originally Posted by Nathanael (Post 3160063)
what does
Code:

sudo -s
echo $PATH

give you?

note: sudo echo $PATH is not the same!

Gives me this:

While not root:
Code:

[miroslav@localhost ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/home/miroslav/bin
[miroslav@localhost ~]$

Root - with sudo:

Code:

[miroslav@localhost ~]$ sudo -s
[sudo] password for miroslav:
[root@localhost ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/bin:/bin
[root@localhost ~]#

Root - with su:
Code:

[miroslav@localhost ~]$ su
Password:
[root@localhost miroslav]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/home/miroslav/bin
[root@localhost miroslav]#


colucix 05-21-2008 04:58 AM

You cannot run fdisk without being root. Actually you can, but it does nothing nor spit any error message. I think it checks if your UID is 0 (root) otherwise exits.

kaiwan 05-21-2008 05:02 AM

Quote:

Originally Posted by colucix (Post 3160073)
You cannot run fdisk without being root. Actually you can, but it does nothing nor spit any error message. I think it checks if your UID is 0 (root) otherwise exits.

Problem exist wile I am root as well:

Code:

[miroslav@localhost ~]$ su
Password:
[root@localhost miroslav]# fdisk
bash: fdisk: command not found


jschiwal 05-21-2008 05:25 AM

You need to run "su -" to run as root with root's environment. What is wrong with "sudo /sbin/fdisk"?

Also, .profile or .bash_login are better places to edit your PATH variable. Every subshell you launch will add /usr to path again unless you test for it's presence before adding it.

kaiwan 05-21-2008 05:44 AM

Quote:

Originally Posted by jschiwal (Post 3160098)
You need to run "su -" to run as root with root's environment. What is wrong with "sudo /sbin/fdisk"?

Thanks, that worked:
Code:

[miroslav@localhost ~]$ su -
Password:
[root@localhost ~]# fdisk

Usage: fdisk [-l] [-b SSZ] [-u] device
E.g.: fdisk /dev/hda  (for the first IDE disk)
  or: fdisk /dev/sdc  (for the third SCSI disk)
  or: fdisk /dev/eda  (for the first PS/2 ESDI drive)
  or: fdisk /dev/rd/c0d0  or: fdisk /dev/ida/c0d0  (for RAID devices)
  ...
[root@localhost ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin:/sbin:/root/bin

Nothing is wrong with "sudo /sbin/fdisk",
but I wanted to explore other options.

Quote:

Originally Posted by jschiwal (Post 3160098)
Also, .profile or .bash_login are better places to edit your PATH variable. Every subshell you launch will add /usr to path again unless you test for it's presence before adding it.

Not sure I understand what to do ?

jschiwal 05-21-2008 06:07 AM

If you don't have a ~/.profile or ~/.bash_login file you can create one yourself and put the same "export PATH=PATH:/usr" command there instead of in ~/.bashrc.

When you login, your .profile might source your .bash_rc file. When you open a new terminal, such as konsole, ~/.bashrc will be run again, and your PATH variable will end with ":/usr:/usr". Some PATH variables contain many more paths, for example adding directories for KDE, Gnome & Java. Having them repeated two or three times in PATH may waste some time searching in the same directories more than once.

kaiwan 05-21-2008 06:15 AM

Quote:

Originally Posted by jschiwal (Post 3160140)
If you don't have a ~/.profile or ~/.bash_login file you can create one yourself and put the same "export PATH=PATH:/usr" command there instead of in ~/.bashrc.

When you login, your .profile might source your .bash_rc file. When you open a new terminal, such as konsole, ~/.bashrc will be run again, and your PATH variable will end with ":/usr:/usr". Some PATH variables contain many more paths, for example adding directories for KDE, Gnome & Java. Having them repeated two or three times in PATH may waste some time searching in the same directories more than once.

thanks, I will try to do that!

Nathanael 05-21-2008 06:40 AM

would it search more than once? i thought when a file is searchd in $PATH it stops after the first match...

chrism01 05-21-2008 07:14 PM

Y, but if it doesn't find it, it'll continue to search every dir in the PATH, each time it appears...!


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