Advertisement

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

Started by March 30, 2004 10:00 AM
4 comments, last by clum 20 years, 7 months ago
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)
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
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...
Advertisement
like this:

export var=value

_don''t_ put a space between the var name and the value

hope that helps
Matt
Matt
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.

Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine

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)
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
Um just edit ~/.bashrc and in it do export duck="andcover"
Um..

This topic is closed to new replies.

Advertisement