|
Using PHP As A Shell Scripting Language
Passing arguments to the shell script
Commonly with a shell script you need to pass arguments to the script.
This is easily done using the built-in
'$argv' array as show in the
following example:
#!/usr/local/bin/php -q
<?php
$first_name = $argv[1];
$last_name = $argv[2];
print("Hello, $first_name $last_name! How are you today?\n");
?>
So in the above script we're printing out the first two arguments
to the script which would be called like this:
[dbrogdon@artemis dbrogdon]$ scriptname.ph Darrell Brogdon
Which would print out:
Hello, Darrell Brogdon! How are you today?
[dbrogdon@artemis dbrogdon]$


