List of exit codes on Linux

When a script or process exits or is terminated by some other means, it will have an exit code, which gives some indication about how or why the script or process ended. For example, an exit code of 0 means that the process exited without error – in other words, it completed its task and exited as expected. On the other hand, an exit code of 1 means that the process encountered some kind of error upon exiting.

In addition to those two exit codes, there are a slew of other reserved codes in Bash that have their own meanings. In this tutorial, we will show you a list of exit codes on a Linux system, and explain what each of them mean.

In this tutorial you will learn:

  • What is an exit code in Linux?
  • How to retrieve an exit code in Bash
  • List of reserved exit codes in Bash
List of exit codes on Linux
List of exit codes on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Bash shell
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

List of exit codes on Linux




Now that you know what an exit code is, let’s see how to retrieve the exit code for a script or process that has ended. As an example, we will run a short script and then view its exit code. The command to see an exit code is echo $?

$ ./script.sh
$ echo $?
0

In the example above, we have an exit code of 0, implying that the script terminated as expected.

You will find a list of exit codes and their meanings in the table below.

Exit code Description
0 Successful exit without errors
1 One or more generic errors encountered upon exit
2 Incorrect usage, such as invalid options or missing arguments
126 Command found but is not executable
127 Command not found, usually the result of a missing directory in $PATH variable
128+N Command encountered fatal error (was forcefully terminated manually or from an outside source). The N tells us which signal was received (see example below)
130 Command terminated with signal 2 (SIGINT) (ctrl+c on keyboard). 128+2
143 Command terminated with signal 15 (SIGTERM) (kill command). 128+15

Closing Thoughts

In this tutorial, we learned about what an exit code is in Bash, how to retrieve an exit code, and a list of common exit codes and their meanings on a Linux system. Retrieving exit codes and knowing their meanings is important for a Linux administrator in order to determine how or why a process or script ended. The exit codes can tell you if the script exited gracefully or if an error occurred.



Comments and Discussions
Linux Forum