-   Linux - Newbie (
-   -   Export variable (

loopoo 08-05-2005 10: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

rstewart 08-05-2005 04:18 PM


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

in "shell1" (executable bash shell script)

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

in "shell2" (executable bash shell script)

#! /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 07:45 AM


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

loopoo 08-08-2005 02:46 AM

Thanks a lot!
That worked just fine!

loopoo 08-08-2005 05: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?


All times are GMT -5. The time now is 09:44 PM.