Skip to content

/errors/bash/command-not-found

bash: command not found (exit status 127)

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
tool
Bash
exit code
127
versions
bash 4.x, bash 5.x
os
linux, macos, windows

bash prints command not found when it cannot find an executable with that name in any directory listed in PATH. The command then fails with exit status 127. The usual causes: the program is not installed, its directory is not in PATH, or the name is misspelled.

Reproduce the error

bash
nonexistent-tool --version
echo "exit status: $?"

Output

bash: line 1: nonexistent-tool: command not found
exit status: 127

Run interactively, bash omits the line N: part and prints bash: nonexistent-tool: command not found.

Check whether the shell can find the program

command -v prints the path bash would run, or nothing with exit status 1 when the name cannot be resolved.

bash
command -v ls
command -v nonexistent-tool || echo "not found (exit status $?)"

Output

/usr/bin/ls
not found (exit status 1)

Fix: add the program's directory to PATH

When the program exists but lives outside PATH, add its directory, or call it by its full path.

bash
mkdir -p "$HOME/tools"
printf '#!/bin/sh\necho hello from mytool\n' > "$HOME/tools/mytool"
chmod +x "$HOME/tools/mytool"
mytool || echo "exit status: $?"
export PATH="$HOME/tools:$PATH"
mytool

Output

bash: line 4: mytool: command not found
exit status: 127
hello from mytool

To make the change permanent, put the export PATH=... line in ~/.bashrc (interactive shells) or ~/.profile (login shells).

Other causes

  • Not installed. Install the package that provides the program, then open a new shell or run hash -r.
  • Misspelled or wrong case. Command names are case-sensitive on Linux and macOS: Python is not python.
  • Moved program. bash caches command locations; after moving a program, hash -r clears the cache.

FAQ

What does exit status 127 mean in bash?

127 means the command was not found: bash searched every directory in PATH and found no executable with that name.

Why does a script work in my terminal but fail in cron with command not found?

cron starts jobs with a minimal PATH. Use full paths to programs or set PATH at the top of the crontab or the script.

Sources