Link to home
Start Free TrialLog in
Avatar of Alaska Cowboy
Alaska CowboyFlag for United States of America

asked on

Unix script, how to pass return code back to calling script(s)

I have 4 scripts called in succession, and need to pass the return code back from each called script to the calling script. How can I do that ? I have the return code, just don't know how to receive it in the calling script.

Currently:
My_Calling_Script A, last step:

     my_called_script.ksh $parm1 $parm2

     (how do I receive back $return_code)

-----
my_called_script:

     return $return_code (I'll be adding this new to my script)
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alaska Cowboy

ASKER

Ok, let me give it a shot, thank you.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have this which works fine:

$my_called_script.ksh <$maindir/dirList.lst $this_subj_area $return_code

at the end I say

return $return_code

but in the called script it's not working:

   $my_called_script.ksh $maindir $this_source $this_Subject_Area
   return_code = $?
   echo 'Clean verify, return code = ${return_code}'
   return ${return_code}

the debugging shows:
+ return 0
my_called_script.ksh[183]: return_code not found
Clean verify, return_code = ${return_code}

I will check this tomorrow, heading out, thanks.
Omit the spaces around the equal sign in the variable assignment and it will work!

return_code=$?

And don't use single quotes with echo if you want to have the variable resolved:

 echo "Clean verify, return code = ${return_code}"
Ok, thanks, will try again tomorrow.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gerwinjansen - ok, checking this out now, thank you.
Ok, looks like I got it working . . . here is the output:

+ return 16
my_script_1, return code = 16
my_script_2, the return code = 16

so it's passed back up twice and looks good on the output.

I'm trying to see if this will cause the CA-7 job scheduler to show an abend, will leave it open for 24 hours.

gerwinjansen - didn't know about calling the script like a function, good to know.
sorry for the delay, this worked great, closing out now.