Michael Michael - 9 months ago 25
Bash Question

How to send a path directory as a parameter to a php script?

I need to give a path to a folder as an input to a php script so that my php script will do certain things depending on the path. From the linux terminal (Debian), I run my program with the command:

php /path/name/example.php

If I write:

php /path/name/example.php pwd

I would expect it to pass in the present working directory into my php script but it doesn't. I
echo argv[1]
which is what is passed into the script, and it only prints out "pwd", instead of the directory. How can I send the directory as a parameter to my script?



You need to use command substitution using $() or back ticks.

$php prog.php $(pwd)

The $() executes the command, (pwd here) and pass the output as argument to the php script.