Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Scripting - Not returning to calling script 1

Status
Not open for further replies.

wdellin

MIS
Feb 8, 2002
36
US
I have a unix korn script that executes another script. If the called script detects an error it does an exit or exit 1. This does not return to the calling script. How do I code the script to return regardless of what happens in the calling script.

Script A

. ${path}/script_B

Script_B
echo 'This is executed from script_A'
if [ -e ${path}/goodfile ]
then
echo 'File exists'
else
echo 'when I do this exit it does not go back to script_A'
exit 1
fi
if [ -e ${path}/badfile ]
then
echo 'when I do this exit it does not go back to script_A'
exit 2
fi
echo 'If it comes here it will return to script_A'
 
This is just because scriptA is sourcing scriptB.
Replace this line:
Code:
. ${path}/script_B
by this:
Code:
${path}/script_B
And you'll be able to test the exit code ($?) of scriptB.



Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
It may need to be sourced if the called script is defining environment variables that the calling script needs. In this case, just replace the "[tt]exit[/tt]" with "[tt]return[/tt]". This will return to the called script passing the return value to it.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top