How to Use Linux Exit Codes to Troubleshoot Your Linux System
1 min read
Summary
Exit codes, also known as return codes or exit statuses, are numerical signals that a program, command or script sends back to the operating system or calling process after it has completed its execution.
In Unix-like shells, it is common practice to check the exit code of the last executed foreground command by inspecting the $? special shell variable.
Generally, an exit code of 0 is used to indicate that a program has executed successfully, while other values indicate various errors, and the specific number often provides information about the type of problem that occurred.
Exit codes can be especially useful when writing shell scripts, as they allow the script to determine whether something went right or wrong and decide what to do next.
In this article we explore how to use exit codes, check the status of the last command executed and set your own exit codes to indicate different types of errors.