Make a script executable
-
Add a shebang at top of the file (recommended):
-
Give execute permission:
-
More controlled (common choices):
Numeric breakdown: r=4, w=2, x=1. Example 755 = 4+2+1 (owner) : 4+1 (group) : 4+1 (others).
Check current permissions
Run the script
-
If executable:
./script.sh -
Without making executable:
bash script.shorsh script.sh
Change owner/group (if needed)
Make many scripts executable
Common gotchas
CRLF line endings (Windows) cause /bin/bash^M: bad interpreter errors — fix with dos2unix script.sh or sed -i 's/\r$//' script.sh.
/bin/bash^M: bad interpreter errors — fix with dos2unix script.sh or sed -i 's/\r$//' script.sh.-
If you still get permission denied, check parent directory execute/search bit: you need
xon directories to traverse them. -
If script is on a mounted filesystem with
noexecoption, you cannot execute — run viabash script.shor remount withoutnoexec.
If you want, tell me:
-
the filename and desired access (only you vs everyone), and I’ll give the exact command to run; or
-
paste
ls -l script.shoutput and I’ll interpret it.
