|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Return variable value from a script running in background
I have a script which runs a script in the background. Now the script running in background returns some variable value and i want to catch return value in the parent script. e.g. Parent Script : Code:
#!/bin/bash ./Back.sh & pid=$! echo "a=$a" echo "b=$b" echo "d=$((a+b))" wait $pid Child Script run in background Code:
a=4 b=5 c=6 Now when i run ./BackGroundProcess.sh , expected output is : a=4 b=5 d=9 what i get is a= b= d=0 Any suggestions or approach how I can retrieve a variable value from a script running in background ? |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks rangarasan.
![]() |
|
#4
|
||||
|
||||
|
A child script cannot pass variables to a parent script. There are ways to read the output of the child script in the parent script. For example: Code:
$ cat back.sh echo 4 5 $ cat fore.sh TESTFIFO=./testfifo mkfifo "$TESTFIFO" ./back.sh > "$TESTFIFO" & echo hello read a b < "$TESTFIFO" echo "a=$a" echo "b=$b" echo "d=$((a+b))" rm "$TESTFIFO" $ ./fore.sh hello a=4 b=5 d=9 Alternatively, ksh93 and bash 4 can use coprocesses Last edited by Scrutinizer; 12-26-2012 at 09:18 AM.. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks dude.
Though I already tried this approach by redirecting output to TEMP.sh from the script running in background and then calling ./TEMP.sh from the script running in forground. Though thanks for your input. ![]() ![]() TR, Shaishav |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| expect_out buffer no such variable running script background | shellscripter | Shell Programming and Scripting | 0 | 10-01-2010 01:34 AM |
| Running script in background | shahnazurs | UNIX for Advanced & Expert Users | 3 | 06-04-2009 01:26 AM |
| Running the Script in Background. | prabhutkl | UNIX for Dummies Questions & Answers | 2 | 05-13-2009 12:44 AM |
| send a new value to a variable in a running background process | razziel | UNIX for Advanced & Expert Users | 2 | 04-22-2009 10:57 AM |
| How to export a variable from a child process running in background to the parent | aixjadoo | Shell Programming and Scripting | 3 | 11-14-2008 04:35 AM |
|
|