LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Export variable (https://www.linuxquestions.org/questions/linux-newbie-8/export-variable-350263/)

loopoo 08-05-2005 09:23 AM

Export variable
 
Hi everybody!

I am trying to write a script which will launch some others.
But, i want to get a response from the first script that will be executed by the main one, and, after receiving that, launching some other scripts.

Is it possible do pass a variable from the main script to another one, and then pass it back and check its value?

I am using bash on AIX 4.2

Thanks in advance
LooPoo

rstewart 08-05-2005 03:18 PM

Hi,

Sure you can. Take a look at the following two shell scripts:

in "shell1" (executable bash shell script)
Code:

#! /bin/bash
Var1="1"
Var2="3"
Var3=`shell2 $Var1 $Var2`
echo "Var3: " $Var3

in "shell2" (executable bash shell script)
Code:

#! /bin/bash
Var1=`expr $1 + $2`
echo $Var1

You can see that shell1 sets up a few variables and passes those variables to shell2. shell2 takes those variables as input arguments, sums them and echos the results. shell1 gets the echoed data from shell2 and assigns it to a third variable. shell1 then goes on to echo out the results to the screen.

eddiebaby1023 08-07-2005 06:45 AM

Quote:

I am using bash on AIX 4.2
Why? You can use ksh!

loopoo 08-08-2005 01:46 AM

Thanks a lot!
That worked just fine!

loopoo 08-08-2005 04:08 AM

One problem though...

I still have to echo something else in the child script besides this variable that I want to pass back.
And when I do this, I recieve in the main script everything that I've echoed in the child script.

How can I skip this problem?


Thanks,
LooPoo


All times are GMT -5. The time now is 01:41 PM.