1833110 Members
2767 Online
110051 Solutions
New Discussion

export in scripts

 
SOLVED
Go to solution
Mrg_2
Advisor

export in scripts

Why do people use export with variables in scripts? I can only assume it is to set the environment variables. Are the exports temporary just until the process stops running? I am trying to gain a better understanding on the use of export in scripts.
Examples are below.

export ORACLE_HOME=/oracle/app/product/forms9i
export TWO_TASK=ID
export TERM=vt100
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: export in scripts

Hi:

Yes, one 'export's a variable from a script to propagate it into any child environment.

Yes, the environment exists only for the lifetime of the process and any child processes that inherit the environmental content.

One way to pass variables from one script to another is to "source" or read a file:

# cat /tmp/A
#!/usr/bin/sh
fruit=apple

# cat /tmp/B
#!/usr/bin/sh
. /tmp/A
echo "I want a(n) ${fruit}"

# /tmp/B
I want a(n) apple

...Note the dot character; followed by whitespace; followed by the script to be "sourced" (read). In this case, the variables declared in "A" are only available to "B" for its use.

Regards!

...JRF...
Wouter Jagers
Honored Contributor

Re: export in scripts

Exporting a variable makes it available to child processes.

Easily demonstrated in a shell:

babylon-4:itrc wout$ echo $TEST
value
babylon-4:itrc wout$ sh
sh-3.2$ echo $TEST

sh-3.2$ exit
exit
babylon-4:itrc wout$ export TEST
babylon-4:itrc wout$ sh
sh-3.2$ echo $TEST
value

Cheers
Wout
an engineer's aim in a discussion is not to persuade, but to clarify.
Mrg_2
Advisor

Re: export in scripts

Thanks for the quick replies very helpful.