Exporting Variables
Steve Feehan
sfeehan at sbb.uvm.edu
Mon Jul 11 01:23:43 UTC 2005
On Sun, Jul 10, 2005 at 09:12:32PM -0400, Matthew S-H wrote:
> 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
Because 'set' is a shell builtin. It does not result in a
new process being created, so unexported variables are visible.
> 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
>From the bash(1) man page:
_ At shell startup, set to the absolute file name of the shell or
shell script being executed as passed in the argument list.
Subsequently, expands to the last argument to the previous com-
mand, after expansion. Also set to the full file name of each
command executed and placed in the environment exported to that
command. When checking mail, this parameter holds the name of
the mail file currently being checked.
> 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??
Yes.
--
Steve Feehan
More information about the ubuntu-users
mailing list