Process Exit and Recovery
Exit Status
Decide the Next Step
Shell scripts use exit status values to decide whether later work should continue. Modeling the status keeps the lesson deterministic without exiting the replay.
Program
Play the script to choose a status and see the next-step decision.
exit_status_check.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
status=0
command="validate-config"
if [ "$status" -eq 0 ]; then
result="continue"
else
result="stop:$status"
fi
echo "$command:$result"
#!/usr/bin/env bash
status=2
command="validate-config"
if [ "$status" -eq 0 ]; then
result="continue"
else
result="stop:$status"
fi
echo "$command:$result"
status ← 0
3status=04command="validate-config"values this step0statuscommand ← validate-config
3status=04command="validate-config"5if [ "$status" -eq 0 ]; thenvalues this stepvalidate-configcommandif [ "$status" -eq 0 ]; then
4command="validate-config"5if [ "$status" -eq 0 ]; then6 result="continue"values this step0statusresult ← continue
5if [ "$status" -eq 0 ]; then6 result="continue"7elsevalues this stepcontinueresultecho "$command:$result"
9fi10echo "$command:$result"outputvalidate-config:continuevalues this stepvalidate-configcommandcontinueresult
status ← 2
3status=24command="validate-config"values this step2statuscommand ← validate-config
3status=24command="validate-config"5if [ "$status" -eq 0 ]; thenvalues this stepvalidate-configcommandif [ "$status" -eq 0 ]; then
4command="validate-config"5if [ "$status" -eq 0 ]; then6 result="continue"values this step2statusresult ← stop:2
7else8 result="stop:$status"9fivalues this stepstop:2result2statusecho "$command:$result"
9fi10echo "$command:$result"outputvalidate-config:stop:2values this stepvalidate-configcommandstop:2result
exit status
An exit status is the numeric result of a command.
zero
Status zero conventionally means success.
stop path
A nonzero status should usually stop or recover before continuing.