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
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
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)
/bin/sh
actually exist on your system? Is it a shell binary? Does /bin/sh
have executable (x) permission set?
– Hkoof
Oct 01 '18 at 09:30
/bin/sh
might not be Bash (e.g. Debian and Ubuntu). See e.g. https://unix.stackexchange.com/q/250913/170373
– ilkkachu
Oct 01 '18 at 11:27
/bin/sh
on it) if there's no shebang, or rather, if execve()
doesn't work on it. At least Linux gives ENOEXEC
("Exec format error") instead of EACCESS
("Permission denied") if the file isn't recognized as an executable, so the error message here doesn't really match that situation.
– ilkkachu
Oct 01 '18 at 11:57
dos2unix script.sh
? – Archemar Oct 01 '18 at 12:16noexec
? Check with themount
command. – Kusalananda Oct 03 '18 at 06:53