I have figured that if I want to use./
to execute a script, I have to runchmod +x file
first. But why can I execute it by using sh file
without the chmod
command? Doesn't sh
need any executing permission?
Asked
Active
Viewed 62 times
0
-
In the second case, it only needs to be readable. See What is the difference between sh and ./ when invoking a shell script? – steeldriver Mar 18 '20 at 12:06
1 Answers
1
sh
HAS execution permissions. Well it basically is a symlink to dash.
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Feb 17 2016 /bin/sh -> dash
And dash has execute permissions:
$ ls -l /bin/dash
-rwxr-xr-x 1 root root 154072 Feb 17 2016 /bin/dash
All dash has to do is parse the script so the file needs to be readable.

Rinzwind
- 299,756
-
-
How would you differentiate between listing the file on screen and executing it contents? There needs to be a way to tell the file to execute and you do that with
./
+ executing permissions. (The latter is more a security measure: being able to execute anything is bad). – Rinzwind Mar 18 '20 at 12:26