[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-newbie
Subject:    Re: export variables
From:       Steven Smith <sos22 () cam ! ac ! uk>
Date:       2003-01-24 17:37:32
[Download RAW message or body]

> - -------------- test.sh ------------------
> export MY_VAR="SOME_VALUE"
> echo "$MY_VAR"
> - -------------- test.sh ------------------
> later: chmod +x test.sh then run this script: ./test.sh
>
>   but when try to use this variable in my environment I can't do, if write 
> "env" the nev variable MY_VAR doesn't appear ... I think that there are some 
> protection about export variables, but how do I can export variables?
The environment of a process cannot easily be changed from outside
that process once the process has started running.  This means that
exporting a variable does not do the obvious thing: if you run
a shell script, which tries to export a variable, then that variable
will only be exported to processes which are spawned by that shell
script.  In particular, if test.sh contains

export WIDGET=wobble

then running test.sh will have absolutely no effect on the environment
of the shell which invoked it.

If you need to change a running shell's environment through a script,
then you need to get that shell to source rather the script rather
than to execute it.  To do this, go

$ . ./test.sh

This causes the shell to run test.sh as if it had been typed in at
the command line, rather than spawning an entirely independent shell
and running test.sh through that.

Steven Smith,
sos22@cam.ac.uk.

[Attachment #3 (application/pgp-signature)]
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic