Command not found — Diagnose Bash exit 127
A Bash command lookup failure commonly produces exit status 127. Causes include typos, missing software and PATH excluding the executable. Check command -v and type before installation; a script may also return 127 intentionally, so exit status alone is insufficient. Bash usually returns 126 instead when it finds a command but cannot execute it. If a known executable is outside PATH, use its verified absolute path or correct the intended environment. Do not add writable untrusted directories to PATH. Re-run the original operation and revert temporary PATH changes by exiting the subshell. Run this complete example in a fresh ordinary-user Bash script without errexit (set -e); it intentionally captures a nonzero command status. It requires mktemp, cat and rm. The EXIT trap removes only the directory created by this invocation.
Formal Syntax & Structure
command -v COMMAND; type COMMANDParameters & Attributes
| Name | Type | Description |
|---|---|---|
| COMMAND | operand | Name whose resolution is being investigated |
Return Value
Bash reports 127 for unresolved command; command -v is nonzero for missing command. Diagnostic text varies by shell and locale.
Working Example
d=$(mktemp -d) || exit 1trap 'rm -rf -- "$d"' EXITbash --noprofile --norc -c 'bytemind_missing_v32_command' 2> "$d/err.txt"rc=$?cat "$d/err.txt"printf 'status=%s\n' "$rc"test "$rc" -eq 127 && command -v printf >/dev/null