to read variable from child script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to read variable from child script
# 1  
Old 08-19-2009
to read variable from child script

Hi
I have two shell scripts A and B
A calls B
I would like to use a variable in A the value of which is assigned by
B after calling B
Thanks in advance
Suresh
# 2  
Old 08-19-2009
A quick and dirty way would just be to output that variable into a file and have the other shell script read from it. Would have to see some logic flow of your script to tell you more.
# 3  
Old 08-19-2009
Hi Suresh,

Code:
$ cat a.sh
export VAR_A=9
echo In a.sh VAR_A : $VAR_A
./b.sh

$ cat b.sh
echo In b.sh VAR_A : $VAR_A

$ ./a.sh
In a.sh VAR_A : 9
In b.sh VAR_A : 9
$

# 4  
Old 08-20-2009
Hi Thanks for your replies
Chompy.....thank you but this is the way i do but i thought that there might be another smarter way to do it that is why i posted it

scripter.online .........thank you but echo would work but manupulation of the variable doesnt work
# 5  
Old 08-20-2009
Hey I said it was quick and dirty, didn't say I endorsed it Smilie
# 6  
Old 08-20-2009
Quote:
Originally Posted by ssuresh1999
Hi Thanks for your replies
Chompy.....thank you but this is the way i do but i thought that there might be another smarter way to do it that is why i posted it

scripter.online .........thank you but echo would work but manupulation of the variable doesnt work

Hi ,

Please check

Code:
 
$ cat a.sh
export VAR_A=9
echo In a.sh VAR_A : $VAR_A
./b.sh

$ cat b.sh
echo In b.sh VAR_A : $VAR_A
VAR_A=`expr ${VAR_A} + 9 `
echo In b.sh After adding VAR_A to VAR_A : $VAR_A
$

$ ./a.sh
In a.sh VAR_A : 9
In b.sh VAR_A : 9
In b.sh After adding VAR_A to VAR_A : 18
$


Last edited by scripter.online; 08-20-2009 at 07:07 PM..
# 7  
Old 08-21-2009
exporting the variable is the solution as answered by scripter.online. If echo is working and showing correct data, then check you manipulation code.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script read variable with for

Hi All, How I can read on variable with cycle for in bash script e.g.#!/bin/bash VAR1=`command1 sentence list` for i in $(cat $VAR1); do VAR2=`command2 $i` echo $VAR2 doneSo read VAR1 execute command over this and load in VAR2 then print VAR2, Thanks you, Please wrap... (1 Reply)
Discussion started by: aav1307
1 Replies

2. Shell Programming and Scripting

How to read * in a variable in shell script??

hi, i have a text file which conatins some fields delimited by space. some fields contains * as entries. cron_file.txt 0 * * * * 0 3 * * * i want to read each line 1 by 1 and store each field in seperate variables n a shell script. i am unable to read the field that contains a *. how... (3 Replies)
Discussion started by: Little
3 Replies

3. Shell Programming and Scripting

How to read file and load data into a script as variable

I need to read a text file that contain columns of data, i need to read 1st column as a function to call, and others are the data i need to get into a ksh script. I am quite new to ksh scripting, i am not very sure how to read each row line by line and the data in each columns of that line, set... (3 Replies)
Discussion started by: gavin_L
3 Replies

4. UNIX for Advanced & Expert Users

Value of variable not getting passed in child script

Hi, I am facing a challenge in fixing an issue in my installation scripts.Here is a situation: There are 3 files which are invoked at a below given order: Installer.ksh----->Installer.xml(Ant script)------->common.ksh I am outputting a message from common.ksh at a terminal, after that trying to... (3 Replies)
Discussion started by: baig_1988
3 Replies

5. Shell Programming and Scripting

Script to read input and output files and child scripts

I have a directory where i have *.sas; *.pl;*.sh and *.c scripts I need to find out what are the child scripts and input output files for each script: say I have a shell script which calls a perl script and a sas script: In my first line I want I a) the parent script name; b) the... (1 Reply)
Discussion started by: ramky79
1 Replies

6. Shell Programming and Scripting

How to write script read file and assign it as variable?

Hi all, I want write a csh script which must be able: 1.read a file 2.assign value in file as variable and can i use read in csh script? thx (2 Replies)
Discussion started by: proghack
2 Replies

7. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

8. Shell Programming and Scripting

Passing a variable from a child script back to the parent

Hi I have written a script using ftp to get files from one server and copy them to 2 dirrerent servers. I wish to call this script from a parent script that will check the number of files copied and run a check sum for each file. As the filenames for the files in the get portion of the script... (3 Replies)
Discussion started by: Andy82
3 Replies

9. Shell Programming and Scripting

Shell script to read file into variable

the script i am trying to write will allow my server to give itself an ip address. So far i am up to the following but i'm stuck. tracert -m 1 > traceroute.txt 1 routername (ipaddr) 2.094 ms 1.789 ms 1.243 ms i want to get ipaddr as a variable and use it to write the ifcfg-eth... (7 Replies)
Discussion started by: aspect_p
7 Replies

10. Shell Programming and Scripting

Read variable from file in a C shell script

Hi, I have a 1-line file which looks like " First second third 4 five". I need to extract the number (here 4) in that line and put it in a variable. I will use the variable later to make few tests in my C shell script. Can somebody help me? (2 Replies)
Discussion started by: haouesse
2 Replies
Login or Register to Ask a Question