Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

How do I set an environment variable from a bash script?

This topic is 5163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I do it from .bashrc, then it works fine, but if I do it from any other script, it remains local to the small instant of bash which runs the script. I thought export is supposed to export the variable to other instances of bash, but it isn''t working. I even when so far as to call bash from the script so that it would be a child process but even that doesn''t work (though I''m not surprised because that variable is set to something else in .bashrc). Basically, I have two CVS servers I wish to connect to. I have the $CVSROOT for one of them set in my .bashrc, and I want to be able to enter one command to change the $CVSROOT to the correct value for the other. How do I do this? Zorx (a Puzzle Bobble clone) Discontinuity (an animation system for POV-Ray)

Share this post


Link to post
Share on other sites
Advertisement
you could just source your script like that:
my_pc~#. ./myscript

that way the script gets processed by your current instance and not a new one...

Share this post


Link to post
Share on other sites
i guess his problem is more that he wanna run a script that changes his current environment. sadly this is not possible because each time you run a script it''s executed (even if using the ./ notation) in it''s own process and creates a copy of the environment.

if you want to do this it''s best to use a script like:

...
export CVSROOT=...
/bin/bash
...

i know it''s kinda overkill but you won''t get it otherwise due to unix process management system.

Share this post


Link to post
Share on other sites
quote:
Original post by __tunjin__
you could just source your script like that:
my_pc~#. ./myscript

that way the script gets processed by your current instance and not a new one...
Thank you, this worked.
quote:
Original post by RPTD
i guess his problem is more that he wanna run a script that changes his current environment. sadly this is not possible because each time you run a script it''s executed (even if using the ./ notation) in it''s own process and creates a copy of the environment.

if you want to do this it''s best to use a script like:

...
export CVSROOT=...
/bin/bash
...

i know it''s kinda overkill but you won''t get it otherwise due to unix process management system.
I tried that, but it didn''t work because CVSROOT is actually set to something else in .bashrc.

Zorx (a Puzzle Bobble clone)
Discontinuity (an animation system for POV-Ray)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!