I made a shell script recently to enable windows users on my network to generate pdf's using a virtual network printer on a linux box.

I also got the shell script to execute a php script, the idea being that php would grab the file just created and include it automatically in to the file management system I am building using php.

It works more or less, the php file is executed. Only problem is that I can't figure out how to pass variables to php from a shell script.

I didn't really want to call php indirectly through the webserver as some do, but directly using a line in my shell script like this:

php -f /tmp/test.php?file=$OUTDIR/$2$DATE.pdf

It works, but I can't get it to accept arguments. I have tried a variety of methods for passing variables. I tried it using these variations:

php -f /tmp/test.php variable1=test
php /tmp/test.php variable1=test

Does anybody have a clue how to pass argument s to php without having to invoke an entire URL through a browser?

Greetings,

David.

    does anybody have a clue...

    No, but looking at your examples, I would have also tried ?var=value&var2=value&var3=value...or is that what you were saying with

    php -f /tmp/test.php?file=$OUTDIR/$2$DATE.pdf

    ??

      Yep, those were variables in my shell script. So they would have been passed as in your example. Although looking at the syntax I think the resulting URL might be a bit screwed up.

        But not in this thread. Seems I was way off with my thinking.

        the link is this: http://www.php.net/manual/en/features.commandline.php

        and you can't name the arguments you pass, you can only provide a list of arguments which are placed in an array. So I would have to call php like this:

        php -f test.php -- $OUTDIR $2 $DATE

        Still have to test this and verify that it works in a shell-script file, but it worked from the command line so I figure it should work from a shell script too.

        Linux really seems to kick windows' arse clean out the building when it comes to this sort of thing.

          Write a Reply...