[SOLVED] Want to retrieve exit code of one script into another
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Want to retrieve exit code of one script into another
I have two shell scripts. I am creating a pipeline in which these two scripts will execute in sequential order. But I want to make sure that if the first scripts fails, the second script should not execute. How can I retrieve the exit code of first script into second script?
Suppose I have two scripts:
Now I don't want a third script to invoke this two scripts.
I want to retrieve the exit status code of A.sh in B.sh and then start executing it.
Before starting B.sh, will it be possible for it to check the exit code of previously executed script (A.sh) in B.sh itself.
I tried it before. But actually i am executing these scripts from a GUI. So these two scripts are located at a common location. The application will pick these scripts from the location.
Say it will pick A.sh and start executing it. Now if its successful then only it should be also to run B.sh.
I need a bit of code in the script B.sh which will check the exit status code of A.sh in the script itself.
In short, any script running after the previous script should check the successful execution of the previous script and then proceed.
hope it helps....
In this case the script(s) aren't aware of each others exit codes. You need to add a piece of code to the a.sh script that stores the exit code in a (temporary) file and let script b.sh check that file.
ls -l asdfasdf
echo $ECODE > /tmp/a.exit.code
[[ "$exitcode" != "0" ]] && exit
echo "a.sh ran without error"