开发者

exit status in shell script

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


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


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


$? 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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜