[ubuntu-users] Exporting Variables

Matthew S-H mathbymath at aol.com
Mon Jul 11 01:12:32 UTC 2005


On Jul 10, 2005, at 7:46 PM, 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
>>
>
> And if you go
>
> echo $FOO
>
> you get  bar..

I just want to understand this a little better:

Why does this work:
matt at Whitey:~$ foo=bar
matt at Whitey:~$ set | grep foo
foo=bar

What is "_"?  Where did that var come from??
matt at Whitey:~$ foo=bar
matt at Whitey:~$ export foo
matt at Whitey:~$ set | grep foo
_=foo
foo=bar


And let me just get this correct.  If I ran I put "foo=bar" in my  
"~/.profile", but not "export foo", and then I ran a script that  
tried to use one of these variables in a test construct, it would  
think it was undefined. But if I did run "expert foo", and then I ran  
the script, the script would evaluate it as if it had set it itself??



~Matt



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050710/bd9079b3/attachment.html>


More information about the ubuntu-users mailing list