I have a very simple script.
test.sh
_EXECUTE_METHOD () {
exit 1
}
_EXECUTE_METHOD
ERROR_CODE=$?
if [[ $ERROR_CODE -eq 1 ]]; then
echo "Got error"
exit 0
fi
This script terminate immediately when exit 1 executed inside the function. I want to capture this exit status from function and handle it in the main script.
I have tried set -e & set +e, still no success. I can not use return statement.
Actual output:
$ sh test.sh
$ echo $?
1
$
Actual output:
$ sh test.sh
Got error
$ echo $?
0
$
returnstatement." - Yes, you can! Just try it.thenmissing after the semicolon. Also,[[is nothing but a portability pitfall;[should be used.[altogether. Example