126
BashERRORCriticalExit CodeHIGH confidence

Command not executable

What this means

Exit code 126 is returned by the shell when a command is found, but it cannot be executed. This is almost always due to the file not having execute permissions.

Why it happens
  1. 1The file specified as the command does not have the execute bit set for the current user.
  2. 2The file is on a filesystem mounted with the `noexec` option.
How to reproduce

Attempting to run a script that has not been made executable.

trigger — this will error
trigger — this will error
#!/bin/bash
# Create a script file without execute permission
echo '#!/bin/bash' > ./myscript.sh
echo 'echo "hello"' >> ./myscript.sh
# Attempt to execute it
./myscript.sh
echo "Exit: $?"

expected output

bash: ./myscript.sh: Permission denied
Exit: 126

Fix 1

Add execute permission to the file

WHEN The file is a valid script or binary that you intend to run

Add execute permission to the file
chmod +x ./your_script.sh

Why this works

The `chmod +x` command sets the execute bit, allowing the operating system to run the file as a program.

Fix 2

Execute the script with the shell explicitly

WHEN You do not want to or cannot set the execute permission

Execute the script with the shell explicitly
bash ./your_script.sh

Why this works

Invoking the shell interpreter directly reads and executes the script's commands, bypassing the need for execute permission on the script file itself.

What not to do

Run the script with sudo

This can hide the underlying permission issue and cause the script to run with elevated privileges, which is a security risk.

Sources

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

← All Bash errors