Export to Environment in Scripts
akonstam at trinity.edu
akonstam at trinity.edu
Sat May 7 21:31:19 UTC 2005
On Sat, May 07, 2005 at 01:08:55PM -0400, David Cary Hart wrote:
> I'm trying to export a variable to the environment and then test against
> the environment variable the next time the script is run.
>
> While I can do this from the command line, when export is called from a
> script it doesn't show up in printenv. What am I doing wrong?
> --
think this comes from a misunderstanding of what export does. If you
your have a script that contains exported variables. Executing the
script makes the value of the exported variables available to a subshell
of the shell in which your script runs. After execution of the shell
script the values of the exported variables returns to the value in
the environment of the terminal in which the shell was run.
However if you source the script rather than run it (that is what the
system does with scripts like .bash_profile) then the exported
variables are actually changed in the environment.
As an example if .bash_profile had a value of the PATH exported and
it was run rather than sources the value of the PATH variable would
not change. Sourcing this script would change the PATH variable. You
can run a script and export to the environment.
=======================================================================
Tempt not a desperate man.
-- William Shakespeare, "Romeo and Juliet"
-------------------------------------------
Aaron Konstam
Computer Science
Trinity University
One Trinity Place.
San Antonio, TX 78212-7200
telephone: (210)-999-7484
email:akonstam at trinity.edu
More information about the fedora-list
mailing list