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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-30-2005, 04:35 AM
|
#1
|
Member
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73
Rep:
|
'export PATH' does not work
hello everyone.
I made a simple test.sh script in my ubuntu box which contains 2 lines:
Code:
PATH=$PATH:/home
export PATH
however when I run the script, '/home' still cant be found in my path when i do an 'echo $PATH'.
but when I do an 'export PATH=$PATH:/home' on the command prompt, it works.
can anyone pls help me.
|
|
|
01-30-2005, 05:03 AM
|
#2
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
When you run a script, the shell creates a new sub-shell. That's why it doesn't work. The PATH is updated in the sub-shell, but when the script finishes, that sub-shell and all of its settings (including environment variables) are lost. There is no way to "push" a sub-shell's settings into its parent.
You need to source the file instead of running it. Source'ing a file acts as if you input each line in the file directly at the command prompt. You can source a file in one of two ways:
or the short-hand:
|
|
|
01-30-2005, 09:51 AM
|
#3
|
Member
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73
Original Poster
Rep:
|
hey it worked thanks!
I've a few more questions though. i tried putting the same code in my .bash_profile then closed the terminal and opened another terminal. how come nothing happened. do i need to reset my pc for that?
sorry for this stupid question. i could have found out the answer by restarting the PC myself, but I cant and I dont have the liberty to shut it down.
|
|
|
01-30-2005, 10:01 AM
|
#4
|
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113
Rep:
|
It needs to be a login shell or in your .bashrc. No need to reboot - just logout/in or start a new term.
|
|
|
01-30-2005, 11:06 AM
|
#5
|
Member
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73
Original Poster
Rep:
|
hello
login shell in my .bashrc? what does that mean?
|
|
|
01-30-2005, 11:15 AM
|
#6
|
Member
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73
Original Poster
Rep:
|
hey hey I tried putting my code in .bashrc instead of in .bash_profile and it now works everytime I open up a new terminal.
does this mean that the "proper" way of setting up paths is to put them in .bashrc and not in .bash_profile?
another question. if putting stuff in .bash_profile doesn't do anything, what's the purpose of its existence?
|
|
|
01-30-2005, 11:24 AM
|
#7
|
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290
|
The .bash_profile script is invoked for login shells, and .bashrc for non-login shells (e.g. opening up a new xterm in X). Usually the way to do it is have one source the other so you have a consistent environment regardless of whether the shell is login or non-login.
|
|
|
01-30-2005, 11:39 AM
|
#8
|
Member
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73
Original Poster
Rep:
|
oooh ok. Thanks so much for the help you guys. I guess that's enough enlightenment for today.
I think what I love about linux is I learn so much every day. and the more I learn, the more I see how feeble WinXp is.
|
|
|
All times are GMT -5. The time now is 11:59 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|