English 中文(简体)
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.





相关问题
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 ...

If Python is interpreted, what are .pyc files?

Python is an interpreted language. But why does my source directory contain .pyc files, which are identified by Windows as "Compiled Python Files"?

Do comments slow down an interpreted language?

I am asking this because I use Python, but it could apply to other interpreted languages as well (Ruby, PHP, JavaScript). Am I slowing down the interpreter whenever I leave a comment in my code? ...

Understanding run time code interpretation and execution

I m creating a game in XNA and was thinking of creating my own scripting language (extremely simple mind you). I know there s better ways to go about this (and that I m reinventing the wheel), but I ...

Runtime definition

What is the runtime? And I don t mean "at run time" = as the program/script is running. I mean The <your-interpreted-language-here> runtime

Compiling Ruby and Python interpreters with Clang?

I m just curious; are there any benchmarks about how compiling interpreters for dynamic languages with Clang affects the performance of these languages? Do those interpreters even compile?

热门标签