LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 01-30-2005, 04:35 AM   #1
lemuel
Member
 
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73

Rep: Reputation: 15
'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.
 
Old 01-30-2005, 05:03 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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:
Code:
source filename
or the short-hand:
Code:
. filename
 
Old 01-30-2005, 09:51 AM   #3
lemuel
Member
 
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73

Original Poster
Rep: Reputation: 15
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.
 
Old 01-30-2005, 10:01 AM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
It needs to be a login shell or in your .bashrc. No need to reboot - just logout/in or start a new term.
 
Old 01-30-2005, 11:06 AM   #5
lemuel
Member
 
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73

Original Poster
Rep: Reputation: 15
hello

login shell in my .bashrc? what does that mean?
 
Old 01-30-2005, 11:15 AM   #6
lemuel
Member
 
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73

Original Poster
Rep: Reputation: 15
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?
 
Old 01-30-2005, 11:24 AM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,078

Rep: Reputation: 297Reputation: 297Reputation: 297
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.
 
Old 01-30-2005, 11:39 AM   #8
lemuel
Member
 
Registered: Nov 2003
Location: Cebu, Philippines
Distribution: Ubuntu
Posts: 73

Original Poster
Rep: Reputation: 15
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.
 
  


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
PATH export in etc/profile.local adds dir twice tongar Linux - Newbie 3 06-16-2005 03:56 PM
export $PATH inside script gmitra Programming 3 02-01-2005 08:34 AM
export PATH disappears twallstr Linux - General 4 12-13-2004 02:57 AM
mozilla 1.7 export does not work Villain Slackware 0 07-17-2004 05:48 AM
'export' from a script doesn't work, why? sylvain_gnu Debian 3 04-20-2004 12:42 PM


All times are GMT -5. The time now is 11:49 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration