![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| url calling and parameter passing to url in script | gander_ss | Shell Programming and Scripting | 1 | 05-12-2008 09:45 PM |
| url calling and parameter passing to url in script | gander_ss | UNIX for Advanced & Expert Users | 1 | 05-07-2008 12:34 PM |
| Passing a parameter while calling a script | Rafael.Buria | Shell Programming and Scripting | 2 | 02-13-2008 06:27 AM |
| Passing exit code to calling script | debbiekuch | Shell Programming and Scripting | 2 | 09-18-2006 09:46 AM |
| passing variables to awk from ksh script | rein | Shell Programming and Scripting | 3 | 08-11-2005 11:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
passing a variables value from the called script to calling script using ksh
How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ?
I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if [ $? != 0] then # error processing fi ----- ----- # I want to use the $PID(from the script2 here) Portion of Script 2 ============= ----- ----- # few processing PID=SOMEVALUE ASSIGNED If I use return (exit PID), the problem is, I can not check the script failure or success. I want to use only the variable PID in script1 not the other variables. Thanks for your help. Last edited by rajarkumar; 06-18-2008 at 07:02 PM.. |
|
||||
|
You have this in your script:
PID=SOMEVALUE ASSIGNED Just add the following: Code:
Pid_script2=$PID export Pid_script2 PS: I am assuming script2 runs first.Also you will have to source script1 and script2 so that it does not run in another shell. |
|
||||
|
Thanks for the reply.
Actually script1 runs first and calls script2. If you look at the code sample above. Problem is returning only one variable from script2 at the same I should be able to check the script2 run status using $?. You can have all the variable by executing the script2 inside script1 using . scriptname (inline). The problem is I've same set of variables in script1 and script2, both uses another file for sourcing the common variables. |
|
||||
|
Have the child script open a file, write whatver you want defined., like this:
Code:
#inside child script mypid=$$ echo "PID=$mypid" > /tmp/pidfile # the pid of the child is now recorded in /tmp/pidfile Code:
#parent process tmp=$(child.ksh 1 2 3 ) # now read the file child.ksh wrote chmod +x /tmp/pidfile . /tmp/pidfile # The variable PID is now defined in the parent |
|
||||
|
You could "print" the value to the standard output in script 2:
print $PID or echo $PID In script1 get it to a variable: tmp=`script2 p1 ...` The tmp variable will have your value. You can do the same if you have to return more than 1 value. They will be all in the tmp variable separated by space. To use them put them into "parameters" (don't forget to save true parameters of script 1): set $tmp Now $1 will have the return value 1, $2 - the return value 2, etc. |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|