# Simple Question: using export in sh shell



## overmind (Feb 23, 2011)

If at command line, in a sh shell I do:


```
VAR1=100
export VAR1
echo $VAR1
```

It will display 100.

If I put first two lines in a script file a.sh and the last line in a script file b.sh and then I execute:

```
./a.sh
./b.sh
```

It echoes nothing.
Any idea why?

I've tried before setting VAR1 to do a:

```
set -e
```

and at the end to do a:

```
set +e
```

But still I cannot use/pass VAR1 in second script.


----------



## phoenix (Feb 23, 2011)

Export puts the variable into the environment of the currently running shell, so that any new shells that are started (sub-shells) can read it.

In your example, the export line in a.sh puts the variable into the environment of that shell.  When the script ends, the environment goes with it.  Then b.sh is run, with a clean environment.

You need to either:

call b.sh from within a.sh, or
export the variable in your shell, then run a.sh and b.sh


----------



## overmind (Feb 23, 2011)

In the end I've placed all "global" variables in filename.conf and then in each shell scripts at the begining after #!/bin/sh I've used:

```
. filename.conf
```


----------

