3

I am running a application form the shell script. Now I like to know the exit status of the application to know whether it exit normally or abnormally ( crash etc). How I know it? Example: ./mytestApp

1

4 Answers 4

3

Bash stores the last process' exit value in the special variable $?.

Sign up to request clarification or add additional context in comments.

Comments

3

You can use special variable $? which contains an exit status of the last comand.

Comments

2

$? contains the exit status of the last command executed. So, if the last command was ./mytestapp, $? would contain its exit status immediately after (note that you can only retrieve this value once and it must be retrieved immediately after the command whose exit status you want to know). You may want to capture it in a variable, e.g.

#!/bin/bash
./mytestapp
APPSUCCESS=$?
# Continue doing whatever it is you're doing

This all assumes that you're using bash (sh and zsh will work as well, IIRC).

Comments

0

The special variable $? will contain the exit status of the last command in bash.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.