Exit code 127 error status in Bash script

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
Exit code 127 error status in Bash script
Exit code 127 error status in Bash script
Software Requirements and Linux Command Line Conventions
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 absolute full path to it.

Start by making sure that the command you’re trying to execute is in your $PATH variable:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

If it’s not, you can specify the full path to the command. For example: /bin/who instead of just who.

The other obvious thing to do is to make sure that you’ve spelled your command correctly. Make sure it exists by checking 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, which 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, which would be /usr/bin/tar.




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.



Comments and Discussions
Linux Forum