Why do we need to make file executable when using

2019-06-14 05:14发布

I am a unix newbie and exploring the functionalities of shebang line.

For example, let's say I have a program program.py to execute.

One way to execute is to directly call the interpreter command:

python program.py

If using the shebang line, I will include:

#!/usr/bin/env python 

at the beginning of file to tell the system what interpreter to use.

Then why do we in this case need to make the file 'executable' by calling:

chmod +x program.py

and then call:

./program.py

to execute it,

instead of directly calling:

program.py

to execute it?

1条回答
Melony?
2楼-- · 2019-06-14 05:51

You're asking two unrelated questions.

We make it executable so that the OS reads the shebang line.

We prefix it with "./" so that the shell can find it and tell the OS to execute it, since the script is unlikely to be in a directory listed in $PATH.

查看更多
登录 后发表回答