I use Java to call a shell script in remote machine.
I want to know if the shell execute failed. But I found that, checking the return code $?
after the script is finished doesn't work. $?
only indicate the last command's result code in the script.
So even a command execute failed, but the last command execute success. I can't find it. I want to know how to solve the problem?
Need I check the result code for every command in shell? And if one command execute failed, exit the script?
Best Answer
You can use
set -e
inside the script, or pass-e
to the interpreter when launching.or
http://pubs.opengroup.org/onlinepubs/007904975/utilities/set.html: