ez.no / ezpublish / documentation / development / kernel / executing php shell scripts
These documentation pages are no longer maintained. Please visit the new documentation site.
It's possible to use PHP for shell scripting, however the placement of the PHP binary file are sometimes placed in non-standard directories, so assuming a path generally won't work.
#!/usr/bin/php
And you can't do without a path either since the path to the program must be specified for shell scripts.
#!php
The solution is to use the env program to execute the php binary. You do that by adding this to the top of the php script.
#!/usr/bin/env php
Executing the script is then done by
./myscript.php
Reading input entered from the shell is possible trough the $argv variable. It will be an array with all the input parameters. The first entry in the array (index 0) is always the path to the script, or rather how the script was executed.
foreach ( $argv as $argument ) { if ( $argument == '-h' ) print( "Usage: " . $argv[0] . " -h" ); }
Comments