If you have several versions of Python installed, /usr/bin/env
will ensure the interpreter used is the first one on your environment's $PATH
.
(如果安装了多个版本的Python,则/usr/bin/env
将确保使用的解释器是环境的$PATH
的第一个解释器。)
The alternative would be to hardcode something like #!/usr/bin/python
; (另一种方法是对#!/usr/bin/python
类的东西进行硬编码;)
that's ok, but less flexible. (可以,但是不太灵活。)
In Unix, an executable file that's meant to be interpreted can indicate what interpreter to use by having a #!
(在Unix中,要解释的可执行文件可以通过#!
来指示要使用的解释器#!
)
at the start of the first line, followed by the interpreter (and any flags it may need). (在第一行的开头,接着是解释器(及其可能需要的所有标志)。)
If you're talking about other platforms, of course, this rule does not apply (but that "shebang line" does no harm, and will help if you ever copy that script to a platform with a Unix base, such as Linux, Mac, etc).
(当然,如果您在谈论其他平台,则此规则不适用(但“ shebang行”没有害处,并且如果您将该脚本复制到具有 Unix基础的平台(例如Linux,Mac),将有帮助等)。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…