permissions to bash file

Make a script executable

  1. Add a shebang at top of the file (recommended):

#!/bin/bash
  1. Give execute permission:

chmod +x script.sh # add execute for user/group/others
  1. More controlled (common choices):

chmod 755 script.sh # rwx r-x r-x -> owner can write; others can read+execute chmod 700 script.sh # rwx --- --- -> only owner can read/write/execute chmod 744 script.sh # rwx r-- r-- -> owner write, others read only (but not execute)

Numeric breakdown: r=4, w=2, x=1. Example 755 = 4+2+1 (owner) : 4+1 (group) : 4+1 (others).

Check current permissions

ls -l script.sh # -rwxr-xr-x 1 prabhu prabhu 409 Jun 1 12:00 script.sh

Run the script

  • If executable: ./script.sh

  • Without making executable: bash script.sh or sh script.sh

Change owner/group (if needed)

sudo chown user:group script.sh # e.g. sudo chown prabhu:prabhu script.sh

Make many scripts executable

chmod +x *.sh





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.

  • If you still get permission denied, check parent directory execute/search bit: you need x on directories to traverse them.

  • If script is on a mounted filesystem with noexec option, you cannot execute — run via bash script.sh or remount without noexec.

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.sh output and I’ll interpret it.