-1

I am able to execute a file which has just read permission:

nkrish@maddev2:~$ ls -l NewFile.sh 
-r--r--r-- 1 nkrish nkrish 14 2016-01-14 12:01 NewFile.sh

sh NewFile.sh
.. File gets run... 

Shouldn't file permissions' be r-x in order for this to execute?

Currently user's permission is readonly (r--).

Why is this?

1
  • 1
    It's asked in the second point of the question.
    – kos
    Jan 14, 2016 at 20:25

1 Answer 1

1

You are not executing NewFile.sh, your are executing the command sh, likely /bin/sh passing it NewFile.sh as an argument.

sh happens to read what is in this file and execute it. It doesn't check for execution permission by design, assuming you know what you are doing.

2
  • Also, it wouldn't work if you did ./NewFile.sh. Jan 14, 2016 at 21:12
  • @user4901968 Indeed although that's not the question asked.
    – jlliagre
    Jan 14, 2016 at 21:16

Not the answer you're looking for? Browse other questions tagged .