[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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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"