Results for “exit status”
Small, practical examples. Search by task or narrow things down below.
Branch on a command’s exit status
Linux Commands: Branch on a command’s exit status using GNU/Linux commands in an empty practice directory.
Linux Commands✓ Tested
Check an external process exit status explicitly
PowerShell: LASTEXITCODE reports a native child exit code independently of ordinary PowerShell cmdlet errors.
PowerShell✓ Tested
Preserve a failure status while an EXIT trap runs
Bash Scripts: Capture the status immediately on entry to the trap before running cleanup commands.
Bash Scripts✓ Tested
Use a function’s exit status as a boolean result
Bash Scripts: Return zero for success and test the function directly in a conditional.
Bash Scripts✓ Tested
Handle an expected command failure
Branch on a command’s exit code without aborting the script.
exit status✓ Tested
Increment a counter without an unexpected errexit
Bash Scripts: An assignment avoids the zero-result exit status of a standalone arithmetic post-increment.
Bash Scripts✓ Tested
Test whether tracked working files changed
Git: A quiet diff returns status one for differences, so handle it in a conditional.
Git✓ Tested
Detect an error inside a pipeline
Use pipefail to observe failure before the last pipeline command.
pipefail✓ Tested
Handle an expected child-process failure
Python: Catch CalledProcessError when check=True reports a nonzero exit status.
Python✓ Tested
Return text from a shell function
Capture a function’s output with command substitution.
function✓ Tested
Test whether one revision is an ancestor of another
Git: merge-base --is-ancestor reports its answer through the exit status.
Git✓ Tested
Announce a status update politely
Announce a status update politely with a small React component and explicit browser behavior.
React✓ Tested