LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-03-2011, 02:18 AM   #1
ananthkadalur
Member
 
Registered: Mar 2011
Posts: 38

Rep: Reputation: 0
path variable


Hi...I am using CentOS5.5 & everytime it is showing command not found.
if I export the path as below it will be working fine until a reboot. Again same error i.e command not found if I open new terminal. Everytime I am exporting as below
#export PATH=/sbin/:$PATH
#export PATH=/usr/sbin/:$PATH
#export PATH=/usr/bin/:$PATH
#export PATH=/bin/:$PATH
So can anybody please tell me how can I set these permanently as that the paths should automatically be exported for everyone user whenever the system boots. And command completion also should happen for eg. #fdi(press tab), then it should show available options such as fdisk, etc.
 
Old 08-03-2011, 02:23 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
If you are using bash, then edit your PATH variable in your .profile (or .bash_login) file, which ever is present. Then it will be modified every time you log in.
See the bash info pages. They explain which files are sourced when you log in. If you are using another shell, consult its man pages to determine which shell to use.

On some distro's, /sbin and /usr/sbin/ aren't in a regular users path, and you are expected to include the full path when you use sudo.
 
Old 08-03-2011, 03:05 AM   #3
ananthkadalur
Member
 
Registered: Mar 2011
Posts: 38

Original Poster
Rep: Reputation: 0
path variable

Sir, can you please tell me which file I have to edit from these below with an example.
[linux@cent0primary ~]$ ls -l .bash*
-rw------- 1 linux linux 14858 Aug 3 12:26 .bash_history
-rw-r--r-- 1 linux linux 33 Jan 22 2009 .bash_logout
-rw-r--r-- 1 linux linux 256 Aug 3 12:25 .bash_profile
-rw-r--r-- 1 linux linux 124 Jan 22 2009 .bashrc

Because I edited .bash_profile as below & I checked it by just logout & login again. it is not working.

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


Quote:
Originally Posted by jschiwal View Post
If you are using bash, then edit your PATH variable in your .profile (or .bash_login) file, which ever is present. Then it will be modified every time you log in.
See the bash info pages. They explain which files are sourced when you log in. If you are using another shell, consult its man pages to determine which shell to use.

On some distro's, /sbin and /usr/sbin/ aren't in a regular users path, and you are expected to include the full path when you use sudo.
 
Old 08-03-2011, 03:27 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Edit your .bash_profile file.
Quote:
Originally Posted by bash info page
When Bash is invoked as an interactive login shell, or as a
non-interactive shell with the `--login' option, it first reads and
executes commands 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.
/etc/profile is a system wide file. Changes there will effect all users, not only yourself. On some systems, you leave it alone but edit /etc/profile.local instead. Read the /etc/profile file. It will tell you in the comments if this is advised.

Last edited by jschiwal; 08-03-2011 at 03:36 AM.
 
Old 08-03-2011, 03:32 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
What is the output from these commands:
Code:
cat ~/.bash_profile
source ~/.bash_profile
echo $PATH
BTW, this looks wrong
Code:
PATH1=/sbin/:$PATH /usr/sbin/:$PATH /bin/:$PATH /usr/bin/:$PATH
better
Code:
PATH1=/sbin/:/usr/sbin/:/bin/:/usr/bin/:$PATH
but it does not affect $PATH which is the real problem.
 
Old 08-03-2011, 04:36 AM   #6
ananthkadalur
Member
 
Registered: Mar 2011
Posts: 38

Original Poster
Rep: Reputation: 0
path variable

Hi..please see the below output
[linux@cent0primary ~]$ cat ~/.bash_profile
# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
export PATH
[linux@cent0primary ~]$

There is no output for this below command
[linux@cent0primary ~]$ source ~/.bash_profile
[linux@cent0primary ~]$ echo $?
0
[linux@cent0primary ~]$


[linux@cent0primary ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/linux/bin:/home/linux/bin:/home/linux/bin
[linux@cent0primary ~]$

I added these below two lines before "export PATH" in .bash_profile file in root user's home(/root) directory as well as linux user's home directory.

PATH1=/sbin/:/usr/sbin/:/bin/:/usr/bin/:$PATH
export PATH1

The path variable has been set to only root user and it is working fine i.e we no need to give full path of command. But for linux user it is not working. everytime I have to export the path manually.
As you told I edited /etc/profile and & added path1 entry as below after HISTSIZE

HOSTNAME=`/bin/hostname`
HISTSIZE=1000
PATH1=/sbin/:/usr/sbin/:/bin/:/usr/bin/:$PATH

& also added an entry for path1 in export line as below
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE PATH1 INPUTRC

Although, The path variable is working fine for only root user and not for any other user.
I checked it after 2 reboot also but it is not working apart from root.


Quote:
Originally Posted by catkin View Post
What is the output from these commands:
Code:
cat ~/.bash_profile
source ~/.bash_profile
echo $PATH
BTW, this looks wrong
Code:
PATH1=/sbin/:$PATH /usr/sbin/:$PATH /bin/:$PATH /usr/bin/:$PATH
better
Code:
PATH1=/sbin/:/usr/sbin/:/bin/:/usr/bin/:$PATH
but it does not affect $PATH which is the real problem.

Last edited by ananthkadalur; 08-03-2011 at 04:39 AM. Reason: correction
 
Old 08-03-2011, 06:02 AM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
I have always edited my ~.bashrc file for path and I am all set.
 
Old 08-03-2011, 08:38 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by ananthkadalur View Post
[linux@cent0primary ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/linux/bin:/home/linux/bin:/home/linux/bin
Thanks for the reply with information. The part quoted above shows the ~/.bash_profile is exporting PATH as expected. What is the evidence for the "other user" pat of "Although, The path variable is working fine for only root user and not for any other user. I checked it after 2 reboot also but it is not working apart from root".

If $PATH is not set after the full bash login process then either the users do not have bash for their shell (check /etc/passwd) or one of the other bash initialisation files is unsetting PATH. Is BASH_ENV set?
 
  


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
Add path to $PATH variable alaios SUSE / openSUSE 2 04-19-2009 09:41 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 06:48 PM
Path Variable answerme Linux - Newbie 6 04-19-2008 03:35 AM
PATH variable suavecu Linux - Software 11 01-28-2006 01:44 AM
PATH variable jk21 Linux - Newbie 1 09-28-2004 03:48 PM


All times are GMT -5. The time now is 12:34 PM.

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