I need to check the return codes of two sub-scripts launched from within a wrapper script, using the Bash shell.
If either subscript fails they will produce a negative integer as a return code. If a script has minor errors it will produce a positive integer. I execution is entirely successful the return code will be 0.
I want to create set a variable to have the contents of another variable based on the outcome. Currently I'm using a big ugly if
elif
construct, but it feels like I should be using a case
statement.
Here's my current code:
if [[ "$sumcreate_retval" -lt "0" ]] && [[ "$movesum_retval" -lt "0" ]]
then
script_retcode="$both_warn_err"
elif [[ "$sumcreate_retval" -gt "0" ]] && [[ "$movesum_retval" -gt "0" ]]
then
script_retcode="$both_crit_err"
elif [[ "$sumcreate_retval" -gt "0" ]] && [[ "$movesum_retval" -lt "0" ]]
then
script_retcode="$createwarn_movecrit_err"
elif [[ "$sumcreate_retval" -gt "0" ]] && [[ "$movesum_retval" -eq "0" ]]
then
script_retcode="$createwarn_err"
elif [[ "$sumcreate_retval" -lt "0" ]] && [[ "$movesum_retval" -gt "0" ]]
then
script_retcode="$createcrit_movewarn_err"
elif [[ "$sumcreate_retval" -lt "0" ]] && [[ "$movesum_retval" -eq "0" ]]
then
script_retcode="$createcrit_err"
elif [[ "$sumcreate_retval" -eq "0" ]] && [[ "$movesum_retval" -gt "0" ]]
then
script_retcode="$movewarn_err"
elif [[ "$sumcreate_retval" -eq "0" ]] && [[ "$movesum_retval" -lt "0" ]]
then
script_retcode="$movecrit_err"
else
script_retcode="$success_return"
fi
How should I restructure this?
Note: If this question is better suited to another SE site please let me know.