开发者

Interpretted Scripts: Implicit vs Explicit Execution

In this superuser question I was advised that it is better to execute scripts written in an interpretted language (php, python, etc) by explicitly executing the interpretter and providing the script as an 开发者_运维问答argument, like:

> php script.php

rather than adding a line to the script to tell the OS to execute it, like:

#!/usr/bin/php
<?php
echo "hello world";
?>

Why is this true? My intuition tells me that it's safer, in case the script is moved to a system in which the interpreter's executable is located at a different path, but is that the only reason?


Portability is enhanced if you use this idiom:

#!/usr/bin/env php

but it has drawbacks of its own; see a longer discussion at http://sites.google.com/site/frankpzh/knowledge-library/shebang


Different paths would be the primary reason, especially when binaries start getting stored in x64-denoted paths or installed in /usr/local/bin/php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜