exported variable not persisted after script execution

Posted by Daniele on Server Fault See other posts from Server Fault or by Daniele
Published on 2011-11-30T16:18:58Z Indexed on 2011/11/30 17:58 UTC
Read the original article Hit count: 254

Filed under:
|
|

I'm facing a wierd issue. I've a vm with solaris 11, and trying to write some bash scripts.

if, on the shell, I type :

export TEST=aaa

and subsequently run:

set

I correctly see a new environment variable named TEST whose value is aaa. If, however I do basically the same thing in a script. when the script terminates, I do not see the variable set. To make a concrete example, if in a file test.sh I have:

#!/usr/bin/bash
echo 1: $TEST   #variable not defined yet, expect to print only 1:
echo 2: $USER
TEST=sss
echo 3:  $TEST
export TEST
echo 4:  $TEST

it prints:

1:
2: daniele
3: sss
4: sss

and after its execution, TEST is not set in the shell. Am I missing something? I tried both to do export TEST=sss and the separate variable set/export with no difference.

© Server Fault or respective owner

Related posts about bash

Related posts about solaris