LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 01: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, 01:23 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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, 02: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, 02:27 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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 02:36 AM.
 
Old 08-03-2011, 02:32 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 03: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 03:39 AM. Reason: correction
 
Old 08-03-2011, 05:02 AM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

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

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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



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 08:41 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
Path Variable answerme Linux - Newbie 6 04-19-2008 02:35 AM
PATH variable suavecu Linux - Software 11 01-28-2006 12:44 AM
PATH variable jk21 Linux - Newbie 1 09-28-2004 02:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:44 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
Open Source Consulting | Domain Registration