LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-22-2011, 05:52 AM   #1
littlebigman
Member
 
Registered: Aug 2008
Posts: 457

Rep: Reputation: 32
Question [bash] Exported variable gone after end of script?


Hello

I'm using a simple Bash script to export an environment variable, eg.

Code:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/my/own/dir
echo $PATH
Then, when I need to add /my/own/dir to PATH, I simply run ./update.path.bash.

Problem is, this change only occurs within the context of the script, and doesn't live beyond it.

What is the right way to update an environment variable so that it "sticks"?

Thank you.
 
Old 04-22-2011, 06:05 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,136

Rep: Reputation: 230Reputation: 230Reputation: 230
Hi

When you start a script, it runs in its own process. A process can't set the environment variables of the parent. But you can run a script without starting a new process. To do this, you have to prefix it with "source" or simply ".".

source ./update.path.bash

or

. ./update.path.bash
 
Old 04-26-2011, 02:33 AM   #3
littlebigman
Member
 
Registered: Aug 2008
Posts: 457

Original Poster
Rep: Reputation: 32
Thanks for the tip.
 
  


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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] calling bash script with more than one variable from python script mfb Programming 4 10-12-2010 06:51 AM
bash script: use the directory of the script file as variable? phling Linux - Newbie 12 01-16-2010 07:16 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM


All times are GMT -5. The time now is 07:10 AM.

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