LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-21-2009, 04:05 AM   #1
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
export variable to parent shell


Is there a way to export a variable to parent shell in shell scripting ?
 
Old 05-21-2009, 04:25 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

It is not possible to export a variable from child to parent. You can work around it by letting the child store variable(s) in a (temporary) file and let the parent read them.

Depending on the complexity (are parent and child running at the same time/does one have to wait for the other, stuff like that) you might want to set tokens (in this case an empty file) to streamline the reads and writes.

Hope this helps.
 
Old 01-31-2011, 07:32 PM   #3
dgard
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
If what you want to do is use a shell script to set up some environment variables (this is usually the case), you simply need to invoke the script like this:
Code:
. ./my_script.sh
That will do the trick. You can find the reference in the bash man page.
 
Old 02-01-2011, 03:20 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by dgard View Post
If what you want to do is use a shell script to set up some environment variables (this is usually the case), you simply need to invoke the script like this:
Code:
. ./my_script.sh
That will do the trick. You can find the reference in the bash man page.
This will parse the variables in the current shell, not the parent shell (no child is created when parsing a file, a child is created when you execute the file).

I do believe the OP wanted to export a variable to [the] parent shell in shell scripting, way back in 2009......
 
  


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
making shell "export" variable permanent forever: user/system lambchops468 Linux - Software 4 10-13-2009 05:37 AM
how to export a bash shell variable before init.d process start pnsidhu Linux - Newbie 1 06-04-2008 08:21 AM
How to share the same variable between parent and child process? zwylinux Programming 6 03-26-2007 02:47 AM
variable export in shell MarioT Programming 3 05-16-2006 11:52 PM
Export Shell Variable not working maxhugen Linux - Newbie 6 01-06-2005 10:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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