Jump to content

Setting environment variables in a shell script


Recommended Posts

I tried to temporarily set environment variables in a bash shell script. However, when the script terminates so does the shell and the environment variables are lost. Is there anyway to transfer them to the original running shell?

 

Glitz.

Link to comment
Share on other sites

Qchem's method is more commonly known as sourcing a script file. it does not invoke a separate bash instance to run the script thereby all changes are retained by the current (bash) interpreter. you could do the same by calling

$ source [scriptfile]

 

always remember that shell variables are not normally propagated to child processes unless they are explicitly exported (EXPORT <variable>). the other way around is impossible as a child process cannot transfer their environment variables back to their parent process.

 

i think this information is on the bash how-to in tldp.org. :)

 

ciao!

Link to comment
Share on other sites

Thanks guys!

 

I put the exported variable in the /etc/profile file. Works great!

 

Now I have the latest Glade-2 and Anjuta stuff compiled and operating on LM9.1 at work.

 

Glitz.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...