-1

I'm on a Centos server and when I tried to run

./script.sh

I get the Permission Denied error even after I tried adding chmod +x script.sh.

sh script.sh works though.

UPDATE

The script file starts with #!/bin/sh

3
  • 1
    dos file might trigger end-of-line problem, have you tried dos2unix script.sh ? Commented Oct 1, 2018 at 12:16
  • Does your user have read permission on the script? Commented Oct 3, 2018 at 5:11
  • Is the script located on a partition mounted with noexec? Check with the mount command. Commented Oct 3, 2018 at 6:53

1 Answer 1

1

Most probably your script lacks a "shebang". The system tries to read which interpreting program should be executed to run the script. A "shebang" is recognized by the system if it is on the very first line and starts with #!.

Examples:

#!/bin/bash 
#!/bin/sh 
#!/usr/bin/env python 
#!/bin/sed 

Note that #! is a comment otherwise in most scripting languages, so it will not error out if you run it with a specific interpreting program from the command line like so:

$ bash ./script.sh 

More information: https://en.wikipedia.org/wiki/Shebang_(Unix)

6
  • It has the line #!/bin/sh Commented Oct 1, 2018 at 9:21
  • Does /bin/sh actually exist on your system? Is it a shell binary? Does /bin/sh have executable (x) permission set? Commented Oct 1, 2018 at 9:30
  • What is the difference between a sh and bash hashbang? Commented Oct 1, 2018 at 9:32
  • See stackoverflow.com/questions/5725296/… Commented Oct 1, 2018 at 11:25
  • @Sam, it runs a different shell. Not all systems have Bash, and even on those that do, /bin/sh might not be Bash (e.g. Debian and Ubuntu). See e.g. unix.stackexchange.com/q/250913/170373 Commented Oct 1, 2018 at 11:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.