Command not executable
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.
- 1The file specified as the command does not have the execute bit set for the current user.
- 2The file is on a filesystem mounted with the `noexec` option.
Attempting to run a script that has not been made executable.
#!/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
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
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.
✕ 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.
GNU Bash Manual
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev