LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 05-20-2009, 11:07 AM   #1
imprise
LQ Newbie
 
Registered: May 2009
Distribution: SUSE
Posts: 20

Rep: Reputation: 0
Changing PATH variable...


Hi all;

Suppose I have created /etc/opt/mydb directory to store my applications executable and I want to add this path to my PATH environment variable. Right?

For this reason, I execute the following command:

PATH=$PATH:/var/opt/mydb

and everything works fine. But when I open a new shell prompt and the issue the echo $PATH command, the new variable does not show?

How can I solve this problem?

Thanks
 
Old 05-20-2009, 11:39 AM   #2
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
The fix depends on what shell you are running. You have to add your path change into the shell startup file. For bash, it would be .bashrc in your home directory. For ksh it would be the .kshrc file.

If you don't have one in your home directory, you are probably using a system default one. For bash, that would be, /etc/bashrc file. You probably shouldn't modify that one, but copying it into your directory as a .bashrc may work, and you can modify that one.

Last edited by nuwen52; 05-20-2009 at 11:44 AM.
 
Old 05-20-2009, 12:07 PM   #3
imprise
LQ Newbie
 
Registered: May 2009
Distribution: SUSE
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by nuwen52 View Post
The fix depends on what shell you are running. You have to add your path change into the shell startup file. For bash, it would be .bashrc in your home directory. For ksh it would be the .kshrc file.

If you don't have one in your home directory, you are probably using a system default one. For bash, that would be, /etc/bashrc file. You probably shouldn't modify that one, but copying it into your directory as a .bashrc may work, and you can modify that one.
Thanks for your reply. I know that I must include it to my bash configuration files. But I read on a book that when I execute the "export variable" command, before I reboot the system, I can use the variable in any other shells that I open afterward. But the command does not work...
 
Old 05-20-2009, 12:24 PM   #4
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,272

Rep: Reputation: 148Reputation: 148
Add this PATH & export PATH in to your /etc/profile file
 
Old 05-20-2009, 12:51 PM   #5
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
If I am misunderstanding what you said, just ignore this.

I could be wrong, but I don't think any changes you make to PATH would carry over past a reboot unless you add something to either the profile or rc file for that shell. And, I think that goes for any variables you define in a shell, whether you export or not. Now, if you change the value of a variable, then spawn an new shell from the one you modified it in, that variable is available.

Example.
# PATH2=newpath;export PATH2
# /bin/ksh
$ echo $PATH2
newpath

Last edited by nuwen52; 05-20-2009 at 12:55 PM.
 
Old 05-20-2009, 01:09 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by imprise View Post
Thanks for your reply. I know that I must include it to my bash configuration files. But I read on a book that when I execute the "export variable" command, before I reboot the system, I can use the variable in any other shells that I open afterward. But the command does not work...
That's not quite correct. When you export a variable it will be inherited from child processes, that is from every subshell which is child of the current shell. But if you open another session (terminal) you start another parent shell which does not know anything about the changes made in the first.

In summary, every open terminal on your desktop has its own environment as set up by the initialization files (/etc/bashrc, /etc/profile, ~/.bash_profile, ~/.bashrc and so on). Any local change is ignored from the other shells.
 
  


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
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 06:48 PM
Changing my PATH variable. sjordan Linux - General 2 03-06-2007 11:08 AM
Changing the PATH variable pppaaarrrkkk Linux - Newbie 1 12-01-2005 10:00 PM
changing path environment variable iNET_boss Linux - Newbie 2 07-27-2005 05:35 PM
Changing $PATH env variable alzogbi Linux - Newbie 2 03-26-2004 03:06 AM


All times are GMT -5. The time now is 06:53 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