Hi all - new here and to php - would post to "newbie" but this section seems more appropriate.

I'm trying to pass a variable to a shell script from a php page.
The php page has the code

<?php exec("./testdoc.sh $version"); ?>

This runs the script testdoc.sh which consists of:

#!bin/sh
export $version
cp template.xml template.$version.xml

The whole lot takes place in a directory owned by the web user, and the shell script executes fine, but the variable isn't being passed or received properly.
Am I using the correct syntax?
Thanks,
Jenny.

    Hey,

    You have it right as long as $version contains something.

    Also, you're sh script is using incorrect syntax... It should be:

    #!/bin/sh 
    export version=$1 
    cp template.xml template.$version.xml 
    

      $version does indeed hold a value. The
      export version=$1
      was the recalcitrant line. Thanks, I've been searching for a way to get this to work all day.
      joy
      Ergates

        Sorry - back with this one again.
        But....what I do if $version is a sentence? Using
        version=$1 only grabs the first word.
        The line I am using to execute the shell script is

        exec("./swtestdoc.sh $version");

        I've tried various combinations of single quotes, double quotes round various things, the only way I can get it to work is if I put a $n for each word, as in
        version=$1$2$3$4

        which isn't much use.

        Thanks!
        Jenny.

          Originally posted by ergates
          Sorry - back with this one again.
          But....what I do if $version is a sentence?....

          exec("./swtestdoc.sh $version");

          I've tried various combinations of single quotes, double quotes round various things...

          Hm. Have you tried escaping your quotes:

          exec("./swtestdoc.sh \"$version\"");

          so's they get passed on to the shell command line? Just a thought. It's tripped me up on occasion.

            Originally posted by Weedpacket


            Hm. Have you tried escaping your quotes:

            exec("./swtestdoc.sh \"$version\"");

            so's they get passed on to the shell command line? Just a thought. It's tripped me up on occasion.

            Nope, that doesn't work either, thanks, though. The value of $variable seems to be passed to the shell script ok, the problem is in the shell script
            version=$1 part.
            Not really a php question really, I suppose. :-(

            Jen.

              Write a Reply...