Glitz Posted November 25, 2003 Report Share Posted November 25, 2003 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. Quote Link to comment Share on other sites More sharing options...
liquidzoo Posted November 25, 2003 Report Share Posted November 25, 2003 put them in the bashrc file maybe? Quote Link to comment Share on other sites More sharing options...
fuzzylizard Posted November 25, 2003 Report Share Posted November 25, 2003 Theortically, I think there is a way of doing that, however, if you want to keep them long term then you need to put them into the .bashrc or .profile file. This should ensure that they are loaded each time you log in. Quote Link to comment Share on other sites More sharing options...
Qchem Posted November 25, 2003 Report Share Posted November 25, 2003 don't start the script with #!/bin/bash and don't finish it with exit 0, then just run the script as . /path/to/script it works for me [tm] Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted November 25, 2003 Report Share Posted November 25, 2003 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! Quote Link to comment Share on other sites More sharing options...
Glitz Posted November 25, 2003 Author Report Share Posted November 25, 2003 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.