Exporting Variables

Steve Feehan sfeehan at sbb.uvm.edu
Mon Jul 11 01:01:28 UTC 2005


On Sun, Jul 10, 2005 at 04:46:24PM -0700, Vram wrote:
> On Sun, 2005-07-10 at 19:17 -0400, Steve Feehan wrote:
> > On Sun, Jul 10, 2005 at 07:09:15PM -0400, Matthew S-H wrote:
> > > What exactly is the purpose of "exporting" a variable?
> > 
> > Setting a variable:
> > 
> >   $ FOO=bar
> > 
> > Only affects the current shell. If you type printenv, the
> > variable won't be set since it's not "exported" to child
> > processes:
> > 
> >   $ printenv | grep FOO
> > 
> > But:
> > 
> >   $ export FOO
> > 
> > Now FOO is exported to child processes, so it will show up
> > in the output of printenv:
> > 
> >   $ printenv | grep FOO
> >   FOO=bar
> > 
> > Hope that helps.
> > 
> > -- 
> 
> And if you go
> 
> echo $FOO
> 
> you get  bar..
> 
> Thanks
> 
> Vram

But this has nothing to do with the variable being exported.
You would get this same result in either case, since the shell
replaces $FOO with 'bar' before executing 'echo'. And to pick
even further, typically 'echo' is a shell builtin and does not
result in a child process.

-- 
Steve Feehan




More information about the ubuntu-users mailing list