Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why running a python file doesn't require the execute permission?

Why running a python file doesn't require the x permission when running it like this:

python script.py

But it does when it's being run as:

./script.py
like image 396
Forge Avatar asked Mar 08 '16 11:03

Forge


2 Answers

Because what you are running with python script.py is the python program; then, it loads and runs the script that you specified in parameters, that is script.py (basically a text file). The script file doesn't need to be an executable because what is executed here is the python interpreter (the python binary itself, that should obviously have the x permission).

With .\script.py, you try to run directly your script (still the same text file) as a program. When you do that, you want it to be parsed with the interpreter that you specified in the first line of your script code, the "shebang", e.g. #!/usr/bin/env python. If it's not set with the x permission, the OS doesn't try to "execute" your file (though it might try to open it with the default program, where applicable), so, it will not care about the shebang.

like image 77
cedbeu Avatar answered Sep 21 '22 06:09

cedbeu


The file itself it interpreted (read) rather than actually executed in your first example. The python application is what needs execute rights.

In the second example the file itself is being executed, so needs those rights in order to proceed.

like image 24
Gareth Webber Avatar answered Sep 20 '22 06:09

Gareth Webber