开发者

Interpretted Scripts: Implicit vs Explicit Execution

开发者 https://www.devze.com 2023-01-08 04:19 出处:网络
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 a

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

精彩评论

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

关注公众号