Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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 I have:

echo 1: $TEST   #variable not defined yet, expect to print only 1:
echo 2: $USER
echo 3:  $TEST
export TEST
echo 4:  $TEST

it prints:

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.

share|improve this question
up vote 8 down vote accepted

export - make variable available for child processes, but not for parent.

source - run script in shell without creating child process

For exalmpe, persistent variable can be realised by writing to file

echo 1: $TEST   #variable not defined yet, expect to print only 1:
if [ -r ${CONFIGFILE} ]; then
  # Read the configfile if it's existing and readable
  source ${CONFIGFILE}
echo 2: $TEST
echo 3: $USER
echo 4:  $TEST
echo 5:  $TEST
share|improve this answer
This is also not exactly what I wanted to achieve, but I got your point. thanks. – Daniele Dec 1 '11 at 19:11

To make your variables visible, you need to source the script which exports your variables. See man source.

share|improve this answer
likely there isn't a source manpage, and you want help source in bash instead. – stew Nov 30 '11 at 17:20
this works if I directly invoke the script, (i.e. if I source the script with the export from the shell), but it doesn't seem to work if I source the script from within another script. – Daniele Dec 1 '11 at 19:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.