[英]Why does python script in current directory need ./ for execution with shebang?
In my current directory there is the executable script.py with the shebang #!/usr/bin/env python
. 在我当前的目录中有带有shebang #!/usr/bin/env python
的可执行脚本script.py。 To execute it in bash, I need to type ./script.py
. 要在bash中执行它,我需要输入./script.py
。 From what I read about shebang I would expect script.py
to execute the script too, same as python script.py
does, but it doesn't. 从我对shebang的了解中,我希望script.py
能执行该脚本,就像python script.py
一样,但事实并非如此。 What is the difference between the two latter options? 后面两个选项有什么区别?
On Un*x-like systems, .
在类似Un * x的系统上, .
is not in the path for security reasons, in order to avoid executing a command like ls
which could be in a user directory (this security breach is best exploited as root) 出于安全原因不在路径中,以避免执行可能位于用户目录中的ls
类的命令(最好以root身份利用此安全漏洞)
This is less concerning for python scripts than for classic commands like ls
, but python scripts with a shebang are executables so the obey the general security rules. 对于python脚本而言,这比诸如ls
之类的经典命令所关心的要少,但是带有shebang的python脚本是可执行文件,因此请遵循一般的安全规则。
When you type python myscript.py
you know that the script is in the current directory, and python
reads it from here, regardless of the system path (it's seen as data , not as executable , the real executable being python
) 当您键入python myscript.py
您知道该脚本位于当前目录中,并且python
从此处读取该脚本,而不管系统路径如何(它被视为data ,不是可执行文件 ,真正的可执行文件是python
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.