Shabang executable path

Gerard Samuel fbsd-questions at trini0.org
Mon Feb 14 19:38:40 GMT 2005


Clint Gilders wrote:

> Gerard Samuel wrote:
>
>> A bit off topic, but I figure someone in here, may be able to point
>> me in the right direction.
>>
>> !#/path/to/php
>>
>> Im wondering, if its possible for the /path/to/php can be made dynamic.
>> i.e.  Have the file still look as if it is a shell script, but
>> the path to the executable is determined at run time,
>> to make it more portable.
>
>
> Seems to me you could use:
>
> #!/usr/bin/env php
>
> Much like people often recommend for perl scripts.


Very nice...

#!/usr/bin/env php
<?php
var_dump($argv);
?>

$ ./z.php -foo bar
array(3) {
  [0]=>
  string(7) "./z.php"
  [1]=>
  string(4) "-foo"
  [2]=>
  string(3) "bar"
}


More information about the freebsd-questions mailing list