0

I have figured that if I want to use./to execute a script, I have to runchmod +x filefirst. But why can I execute it by using sh file without the chmod command? Doesn't sh need any executing permission?

1 Answers1

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
  • Then why ./ need execution permission? Doesn't it work like sh? – Shengyu Liu Mar 18 '20 at 12:21
  • 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