/errors/bash/command-not-found
bash: command not found (exit status 127)
- 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
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.
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.
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"
mytoolOutput
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:
Pythonis notpython. - Moved program. bash caches command locations; after moving a program,
hash -rclears 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.