1

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?

Community
  • 1
  • 1
Jeffrey Blake
  • 9,659
  • 6
  • 43
  • 65

2 Answers2

1

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

lhf
  • 70,581
  • 9
  • 108
  • 149
0

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

Ian Wetherbee
  • 6,009
  • 1
  • 29
  • 30