Set environment variable in bsh script and effect another program.

Set environment variable in bsh script and effect another program.

Post by linux_d » Sun, 31 Dec 1899 09:00:00



Hi,Sir,

How can i set environment variable in a bsh script
and effect another program which is not the script's
child process?

thanks.

Liao.

 
 
 

Set environment variable in bsh script and effect another program.

Post by Graham Wilso » Sun, 31 Dec 1899 09:00:00



> Hi,Sir,

> How can i set environment variable in a bsh script
> and effect another program which is not the script's
> child process?

> thanks.

> Liao.

I don't know if this will help, but did you try "export ENV_VARIABLE"
where ENV_VARIABLE is the name of the variable?

 
 
 

Set environment variable in bsh script and effect another program.

Post by linux_d » Tue, 21 Nov 2000 14:38:18


yes,I did it,but no use.


>I don't know if this will help, but did you try "export ENV_VARIABLE"
>where ENV_VARIABLE is the name of the variable?

 
 
 

Set environment variable in bsh script and effect another program.

Post by Eric » Sun, 31 Dec 1899 09:00:00



> Hi,Sir,

> How can i set environment variable in a bsh script
> and effect another program which is not the script's
> child process?

> thanks.

> Liao.

Unless you source the script that set's the variable, I don't think it's
possible

Eric

 
 
 

Set environment variable in bsh script and effect another program.

Post by mvja » Sun, 31 Dec 1899 09:00:00


Ok I'm not sure if this is what your looking for... But here goes.

If you mean you want to run a script that will set some environmental
variables <or any variable for that matter> then when that script
terminates and you return to the command prompt, you want those variables
to still equal what your script just set them to???

Then there is a workaround... lets say your script is named fix_env
then instead of calling it with

$ fix_env

try calling it with

$ . fix_env

the preceding dot causes the shell to execute the script with it's
current process id <doesn't spawn a child process> so when the script ends
it's process is still the current process and the variable values stay...
Of course you may still have to export them...

Note this can be used to inside another script.

example parent script fragment:

echo "$The_variable"
. fix_env
echo "$The_variable"

If fix_env changes the value of The_variable then the two echo statements
will differ... of course when the parent script terminates... then the
value will revert to it's former value unless the parent script was
called with the . scriptname method too...

        ---   ___
        <O>   <->    Joe (theWordy) Philbrook
            ^


> Hi,Sir,

> How can i set environment variable in a bsh script
> and effect another program which is not the script's
> child process?

> thanks.

> Liao.

 
 
 

Set environment variable in bsh script and effect another program.

Post by Eric » Sun, 31 Dec 1899 09:00:00



Quote:

> Ok I'm not sure if this is what your looking for... But here goes.

> If you mean you want to run a script that will set some environmental
> variables <or any variable for that matter> then when that script
> terminates and you return to the command prompt, you want those variables
> to still equal what your script just set them to???

> Then there is a workaround... lets say your script is named fix_env
> then instead of calling it with

> $ fix_env

> try calling it with

> $ . fix_env

This is called sourcing the script

`source fix_env` will do the same

It's not a workaround, but a very useful feature.
If you eg, edit .bashrc to add some aliases, source the new .bashrc, and
the new aliases will have taken affect. So you don't have to login to
ensure an adjusted rc script is used in your current shell.

Eric