Are you receiving a exit code 127
error when trying to execute a Bash script? This means that your Linux system was not able to find the command referenced inside of the script, which could indicate that the path to the command is not valid, or the command is not installed at all. In this tutorial, we’ll explain what causes this “command not found” error and show you how to fix it.
In this tutorial you will learn:
- What is Bash error 127?
- Remedies for Bash error 127

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | N/A |
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 |
Exit code 127 error status
The 127 error code indicates “command not found”. This occurs when any given command within your Bash script or on Bash command line is not found in any of the paths defined by
PATH
system environment variable.
The solution is to make sure that the command your are using can be found within your $PATH
. If the command is not in your path, either include it or use the absolute full path to the command you are trying to execute.
Let’s first check to make sure that we are spelling the command correctly and that it exists on the system. We can do this with the which
command. For example, here we check the location and existence of the tar
command:
$ which tar /usr/bin/tar
We can see here that tar
is located in the /usr/bin
directory. Next, let’s check to make sure that /usr/bin
is present inside our PATH
environment variable.
$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
In our case, the directory is already in our PATH
variable. If it were not already part of the PATH
variable, then we could reference the full path to the tar
command in our Bash script:
$ /usr/bin/tar [options]
If you find that you need to add a new directory to the PATH variable, see our other tutorial for step by step instructions on how to do that. For additional information about the exit code 127 status, see the EXIT STATUS section of the Bash man page.