You may see a Permission denied error when you try to execute a Python, Shell, or Bash scripts on Linux distributions, Unix, or macOS Terminals.
Example: zsh shell on macOS
% ./script.sh
zsh: permission denied: ./script.sh
Example: Sh Shell
# ./script.sh
bash: ./script.sh: Permission denied
Example: Bash Shell
$ ./script.sh
sh: ./script.sh: Permission denied
Now let's take a look at file permissions using ls command on the script.sh file.
% ls -ls script.sh
0 -rw-r--r-- 1 c2ctechtv staff 0 Jul 16 02:49 script.sh
Let's try to understand what permissions we have on the file using a table.
| Permission | User | Group | Others |
|---|---|---|---|
Read (r) | ✓ | ✓ | ✓ |
Write (w) | ✓ | ||
Execute (x) |
As you can see not of the users have the execute permission enabled, hence the erorr.
Let's make use of chmod +x on the file.
% chmod +x script.sh
% ls -l chmod+x script.sh
-rwxr-xr-x 1 c2ctechtv staff 0 Jul 16 02:49 script.sh
| Permission | User | Group | Others |
|---|---|---|---|
Read (r) | ✓ | ✓ | ✓ |
Write (w) | ✓ | ||
Execute (x) | ✓ | ✓ | ✓ |

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!