Operating System - HP-UX
1754325 Members
2802 Online
108813 Solutions
New Discussion юеВ

Proper SYNTAX for EXPORTing variables

 
SOLVED
Go to solution
Michael Steele_2
Honored Contributor

Proper SYNTAX for EXPORTing variables

Hi:

ScritA calls ScriptB

In ScriptA
SERVER="mecury"
export SERVER

In ScriptB
echo $SERVER

And it prints nada.

What up?
Support Fatherhood - Stop Family Law
5 REPLIES 5
Doug O'Leary
Honored Contributor

Re: Proper SYNTAX for EXPORTing variables

Hey;

Works for me...

$ cat A B
#!/bin/ksh

Server="mercury"
export Server

./B
#!/bin/ksh

echo $Server
$ ./A
mercury

You sure you're not stomping SERVER somewhere in ScriptB?

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Pete Randall
Outstanding Contributor

Re: Proper SYNTAX for EXPORTing variables

What shell are you using?


Pete

Pete
James R. Ferguson
Acclaimed Contributor
Solution

Re: Proper SYNTAX for EXPORTing variables

Hi:

Source 'ScriptA' so that a separate environment isn't created for it:

# . ./ScriptA
# ./ScriptB

...or for that matter, *within* 'ScriptB' do:

...
. ./ScriptA
...

Note that shell sourcing is done with a dot, followed by whitespace, followed by the script name.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Proper SYNTAX for EXPORTing variables

>SERVER="mecury"
>export SERVER

This is the old borne shell way of doing things. In a real shell you can use:
export SERVER="mecury"
Steven Schweda
Honored Contributor

Re: Proper SYNTAX for EXPORTing variables

Note that, as usual, showing an actual
failing test case instead of a vague
description ("ScritA calls ScriptB", where
"calls" is not well defined) would make this
problem easier to diagnose with less reliance
on guesswork/intuition.

Just a thought.