Operating System - HP-UX
1838118 Members
3629 Online
110124 Solutions
New Discussion

Re: export env variable from shell

 
SOLVED
Go to solution
MUM_HPS
Advisor

export env variable from shell

Hi Friends,

here is the small problem,

i want to export ENV variable from Shell Script.

for ex.

i have

test.sh
--------
export TEST=TEsting

#./test.sh

#env ---> i dont see TEST variable set here..

i know that shell variable is different from Environ mental variable. but my requirement is to export a shell variable as a environ mental variable.. let me if any other possibilities.

regards,
Ram
4 REPLIES 4
Robert-Jan Goossens
Honored Contributor
Solution

Re: export env variable from shell

Hi Ram,

Try this

# . ./test.sh

# env | grep TEST

Robert-Jan
B. Hulst
Trusted Contributor

Re: export env variable from shell

Hi,

Either use:

#source ./test.sh

or

#. ./test.sh

Watch the space between the two dots.

Regards,
Bob
Peter Godron
Honored Contributor

Re: export env variable from shell

Ram,
if you run your command as ./test.sh you start up a new shell and the scope of the variable TEST is limited to that shell.

Whereas running the script as . ./test.sh
executes the script within the session you are running from.

The quickest way to demonstrate is to include the line echo $$ in your test.sh and then execute both methods.
The second will return the process id of your session.

Regards
MUM_HPS
Advisor

Re: export env variable from shell

thanks a lot for the quick response. that solved my problem.

thanks once again.

regards,
ram