* [gentoo-user] Environment variables don't export from within scripts
@ 2006-01-02 21:35 Kris Kerwin
2006-01-02 21:48 ` Richard Fish
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Kris Kerwin @ 2006-01-02 21:35 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 728 bytes --]
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
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.
I'm using:
bash-3.0-r12
Is this a bug, or something that I'm doing wrong? Thanks in advance
for your help.
Kris Kerwin
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Environment variables don't export from within scripts
2006-01-02 21:35 [gentoo-user] Environment variables don't export from within scripts Kris Kerwin
@ 2006-01-02 21:48 ` Richard Fish
2006-01-02 21:53 ` Alexander Veit
2006-01-02 22:16 ` Etaoin Shrdlu
2 siblings, 0 replies; 6+ messages in thread
From: Richard Fish @ 2006-01-02 21:48 UTC (permalink / raw
To: gentoo-user
On 1/2/06, Kris Kerwin <kkerwin@insightbb.com> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Environment variables don't export from within scripts
2006-01-02 21:35 [gentoo-user] Environment variables don't export from within scripts Kris Kerwin
2006-01-02 21:48 ` Richard Fish
@ 2006-01-02 21:53 ` Alexander Veit
2006-01-02 22:30 ` Kris Kerwin
2006-01-02 22:16 ` Etaoin Shrdlu
2 siblings, 1 reply; 6+ messages in thread
From: Alexander Veit @ 2006-01-02 21:53 UTC (permalink / raw
To: gentoo-user
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
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Environment variables don't export from within scripts
2006-01-02 21:35 [gentoo-user] Environment variables don't export from within scripts Kris Kerwin
2006-01-02 21:48 ` Richard Fish
2006-01-02 21:53 ` Alexander Veit
@ 2006-01-02 22:16 ` Etaoin Shrdlu
2 siblings, 0 replies; 6+ messages in thread
From: Etaoin Shrdlu @ 2006-01-02 22:16 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Environment variables don't export from within scripts
2006-01-02 21:53 ` Alexander Veit
@ 2006-01-02 22:30 ` Kris Kerwin
2006-01-03 0:38 ` Willie Wong
0 siblings, 1 reply; 6+ messages in thread
From: Kris Kerwin @ 2006-01-02 22:30 UTC (permalink / raw
To: gentoo-user; +Cc: Alexander Veit
[-- Attachment #1: Type: text/plain, Size: 964 bytes --]
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
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gentoo-user] Environment variables don't export from within scripts
2006-01-02 22:30 ` Kris Kerwin
@ 2006-01-03 0:38 ` Willie Wong
0 siblings, 0 replies; 6+ messages in thread
From: Willie Wong @ 2006-01-03 0:38 UTC (permalink / raw
To: gentoo-user
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-01-03 0:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-02 21:35 [gentoo-user] Environment variables don't export from within scripts Kris Kerwin
2006-01-02 21:48 ` Richard Fish
2006-01-02 21:53 ` Alexander Veit
2006-01-02 22:30 ` Kris Kerwin
2006-01-03 0:38 ` Willie Wong
2006-01-02 22:16 ` Etaoin Shrdlu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox