Export Problem

Gregory Woodbury ggw at wolves.durham.nc.us
Sat Aug 28 17:03:18 UTC 2004


On Sat, Aug 28, 2004 at 12:58:41PM -0400, David Cary Hart wrote:
> Perhaps a tad OT. From the command line, if I do "export FOO='bar'" and
> then do export -p, the result is as expected.
> 
> However, if I do the same thing in a script:
> #!/bin/bash
> export FOO="bar"
> 
> . . . it does not create the variable. export -p and it's not there.
> 
> Where am I going wrong? What don't I get? 
> 
> Thanks.

Are you expecting $FOO to be available in the parent context after the
script runs?  A sub-shell cannot effect changes in the parent
environment by adding a variable.  They may be able to chenge the value
of an exported variable handed to them.

If you want the script to change the current context you have to "."
source it into the current shell.  e.g.
	. myscript.sh


-- 
G.Wolfe Woodbury     `- -'
RHCT                   U
The Line Eater is a boojum!





More information about the fedora-list mailing list