Mainframe Path Start learning free
BeginnerError and abend codes126 / 127

Permission denied and exit codes 126 / 127 — command will not run

127 means the shell could not find the command; 126 means it found it but could not run it, usually 'Permission denied'.

What happened

A command or script in a shell, a CI pipeline step or a cron job failed before it did any work. The shell printed an error and set the exit status to 127 or 126.

Bash session (illustrative)Illustrative example
$ mpzip --all
bash: mpzip: command not found
$ echo $?
127
$ ./mpload.sh
bash: ./mpload.sh: Permission denied
$ echo $?
126

What it means

In Bash, 0 means success and any non-zero value means failure; $? holds the status of the last command. Values above 125 have special meanings:

Behind 'Permission denied', the kernel's execve() call failed with EACCES. The man page lists the cases: the file lacks execute permission, a directory in the path does not allow search, the file is not a regular file, or the filesystem is mounted noexec. If a script's #! interpreter path does not exist, execve() fails with ENOENT instead.

Typical causes

Symptoms

Where to look

How to diagnose

  1. Note the exit status: 127 or 126.
  2. For 127, check spelling, check the tool is installed, and compare PATH in the failing environment.
  3. For 126, check the execute bit with ls -l, then directory search permission, then the mount options.
  4. Check the #! line points at a real interpreter on this machine.

How to fix

How to prevent

Production considerations

Interview question

A pipeline step fails with exit code 127. What do you check?

Stuck on something else?
Ask the community or search the full course.

Ask a question