Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting variable

Status
Not open for further replies.

alhassani54

Programmer
Aug 1, 2002
27
GB
Hi

I have two scripts (script1 and script2). Script1 calls Script2.
I tried the scripts below by running script1. The result is null but I would like to have the result of abc = "y" in script1.

Thank you


Script1

#! /bin/ksh
./script1
print "abc="$abc


Script2

#! /bin/ksh
export abc="y"

 
Script 1 runs Script2 (well, actually Script1 but I asume that's a typo) in a separate shell and, as such nothing doen in Script2 will affect Script1.

To get round this you need to use the '.' notation i.e:-
Code:
#!/bin/ksh
#This is script1

. ./script2
print "abc="$abc
script2 stays as you have it.

Ceci n'est pas une signature
Columb Healy
 
Hi,

You can also use functions inside the same script.
Code:
cat script1

#! /bin/ksh
function script2 {
export abc="y"
} # end of function script2

# begin of script1
# call function script2
script2
print "abc="$abc


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top