Re: [gentoo-user] Environment variables don't export from within scripts

2006-01-02 Thread Willie Wong
On Mon, Jan 02, 2006 at 04:30:09PM -0600, Penguin Lover Kris Kerwin squawked:
> Thanks to all for helping.
> 
> The source command did the trick, Alex.
> 
>   ?# echo "export VARIABLE='test'" >> test_script
> # chmod 754 test_script
> # ./test_script
> # echo $VARIABLE
> 
> Get's changed to:
> 
>   # echo "export VARIABLE='test'" >> test_script
> # chmod 754 test_script
> # source ./test_script
> # echo $VARIABLE

Or, you can run it as commands to the current shell by 
   # . test_script
samething as `source', really...

W
-- 
Pintsize: Hello Marten! I wasn't expecting you home this soon. We're playing 
Trolls & Flame-Wars! It's an Internet message-board based role playing game.
Sortir en Pantoufles: up 51 days, 16:58
-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Environment variables don't export from within scripts

2006-01-02 Thread Kris Kerwin
Thanks to all for helping.

The source command did the trick, Alex.

 # echo "export VARIABLE='test'" >> test_script
# chmod 754 test_script
# ./test_script
# echo $VARIABLE

Get's changed to:

# echo "export VARIABLE='test'" >> test_script
# chmod 754 test_script
# source ./test_script
# echo $VARIABLE

Thanks again.

Kris Kerwin

On Monday 02 January 2006 15:53, Alexander Veit wrote:
> Kris Kerwin wrote:
> > I'm having difficulties exporting environment variables from
> > within scripts. The problem doesn't seem to occur when exporting
> > variables from the command line.
>
> The script is executed by a subshell that has it's own environment.
> export does not affect the caller's environment.
> http://www.gnu.org/software/bash/manual/bashref.html#SEC51
>
> The source command (.) may help you.
> http://www.gnu.org/software/bash/manual/bashref.html#SEC56
>
>
> -Alex


pgpv8Y3VlBVjN.pgp
Description: PGP signature


Re: [gentoo-user] Environment variables don't export from within scripts

2006-01-02 Thread Etaoin Shrdlu
On Monday 02 January 2006 22:35, Kris Kerwin wrote:

> works. However,
>
>   # echo "export VARIABLE='test'" >> test_script
>   # chmod 754 test_script
>   # ./test_script
>   # echo $VARIABLE
>
> does not work. I've also tried the above while omitting the 'export'
> command, to the same effect. I'm using bash as my shell. I figured
> that I would try the same with sh instead, but still nothing.

This cannot work. Scripts cannot export back variables to their parent 
shell, but only to their children.

Read the first note here:

http://www.tldp.org/LDP/abs/html/othertypesv.html

The following will work:

# export VARIABLE='test'
# echo '#!/bin/bash' > test_script
# echo "echo $VARIABLE" >> test_script
# chmod 754 test_script
# ./test_script# writes 'test'
-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Environment variables don't export from within scripts

2006-01-02 Thread Richard Fish
On 1/2/06, Kris Kerwin <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm having difficulties exporting environment variables from within
> scripts. The problem doesn't seem to occur when exporting variables
> from the command line.
>
> To reiterate with an example,
>
> # export VARIABLE='test'
> # echo $VARIABLE
>
> works. However,
>
> # echo "export VARIABLE='test'" >> test_script
> # chmod 754 test_script
> # ./test_script
> # echo $VARIABLE

On Linux/Unix, environment variables a passed from parent processes to
children, never the other way around.  This is unlike windows where
environment variables are shared by all processes.

So this is the expected and correct behavior, and thus, not a bug.

-Richard

-- 
gentoo-user@gentoo.org mailing list