[linux] bash vs command line

Evan Martin martine at danga.com
Fri Sep 5 07:40:09 PDT 2003


On Fri, Sep 05, 2003 at 02:21:04PM +0200, =?iso-8859-1?Q? G=FCnther=20Mittermayer ?= wrote:

> #!/usr/bash

> VAR="50"

> echo $VAR

> export VAR

>

> I run the script and it shows the 50 (because of the echo $VAR line),

> but again on the command line:

> $> echo $VAR

>

> won't give me anything, as if the variable simply isn't defined.....

> I am confused... what am I doing wrong??


That "export" only exports the variable into the environment of the
shell that is ran when the script is ran (that's what the /usr/bash is
in there for, though I hope that's a typo).

Use the "source" command to run a script in the current shell's
environment:
$> source ./myscript
$> echo $VAR

(It's also named ".". I'll sometimes do something like:
$> . ./.foo
which is pretty funny looking.)

--
Evan Martin
martine at danga.com
http://neugierig.org


More information about the Linux mailing list