127
BashERRORNotableExit CodeHIGH confidence

Command not found

What this means

Exit code 127 is returned when bash cannot find the command in PATH. The shell searched all directories in PATH and found no matching executable.

Why it happens
  1. 1The command name is misspelled
  2. 2The package containing the command is not installed
  3. 3The directory containing the binary is not in the PATH variable
How to reproduce

A script calls a command that does not exist on the system.

trigger — this will error
trigger — this will error
#!/bin/bash
nonexistent_cmd
echo "Exit: $?"

expected output

bash: nonexistent_cmd: command not found
Exit: 127

Fix 1

Check if command exists before calling

WHEN When the command might not be installed on all systems

Check if command exists before calling
if command -v mycommand > /dev/null 2>&1; then
  mycommand
else
  echo "not found" >&2
fi

Why this works

command -v returns 0 if found in PATH, non-zero otherwise.

Fix 2

Install the missing package

WHEN When the tool is not installed

Install the missing package
apt-get install -y package-name

Why this works

Installing the package places the binary in a standard PATH directory.

What not to do

Ignore non-zero exit codes

Silent failures hide bugs in scripts.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Bash errors