Skip to content

Bash Permission Denied (Executable) Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Bash Permission Denied (Executable) Fix. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Bash raises bash: ./script.sh: Permission denied when the script file does not have execute permissions or the filesystem is mounted with the noexec option.

The Wrong Way

./deploy.sh

Output:

bash: ./deploy.sh: Permission denied

The script file lacks the executable permission bit.

The Right Way

chmod +x deploy.sh
./deploy.sh

Add execute permission with chmod +x before running the script.

Step-by-Step Fix

1. Check file permissions

ls -l script.sh

2. Add execute permission

chmod +x script.sh

3. Run with bash explicitly if needed

bash script.sh

4. Check filesystem mount options

mount | grep noexec

5. Fix shebang line

#!/bin/bash
# Make sure the first line is a valid shebang

Prevention Tips

  • Always run chmod +x script.sh after creating a new script.
  • Use bash script.sh as an alternative to marking a script executable.
  • Check for noexec mount options in container or restricted environments.
  • Verify the shebang line (#!/bin/bash or #!/usr/bin/env bash) is exactly as required.
  • Use chmod 755 script.sh for scripts that need to be readable by everyone.

Common Mistakes with permission denied

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world BASH code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between chmod +x and chmod 755?

chmod +x adds execute permission to the current user, group, and others. chmod 755 sets rwxr-xr-x (read, write, execute for owner; read and execute for group and others). Use chmod +x for simplicity.

Why does my script have permission denied when I run it with bash?

If you run bash script.sh, the file does not need execute permission -- only read permission. If this fails, check that bash is installed and the file is readable.

What does the shebang (#!) do at the top of a script?

The shebang tells the system which Interpreter to use. #!/bin/bash uses bash. #!/usr/bin/env python3 uses python3 from the user's PATH. The shebang is required for direct execution with ./script.sh.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro