Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-05-2005, 09:23 AM   #1
Registered: Aug 2005
Posts: 40

Rep: Reputation: 15
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
Old 08-05-2005, 03:18 PM   #2
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38

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.
Old 08-07-2005, 06:45 AM   #3
Registered: May 2005
Posts: 378

Rep: Reputation: 33
I am using bash on AIX 4.2
Why? You can use ksh!
Old 08-08-2005, 01:46 AM   #4
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks a lot!
That worked just fine!
Old 08-08-2005, 04:08 AM   #5
Registered: Aug 2005
Posts: 40

Original Poster
Rep: Reputation: 15
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?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to export environment variable from a bash script dimaash Linux - Newbie 20 08-09-2011 07:12 AM
cannot export result from awk into a variable in a bash script Emmanuel_uk Linux - Newbie 4 03-07-2005 01:54 AM
Export Shell Variable not working maxhugen Linux - Newbie 6 01-06-2005 10:12 PM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 03:19 AM
BASH variable export Barbarian Programming 2 11-27-2001 08:37 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:10 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration