0

I need to create a bash file with PHP using the phpseclib library. This is the code I am using now:

   $ssh->exec("cat > $sPath$sSavingCode <<EOF
screen -dmS $1 java -Xincgc -Xmx200M -jar craftbukkit-1.4.7.jar nogui
        ");

The code works, and the file saves, but it skips the "$1". instead, it makes a file with two spaces between -dmS and java.

How can I make it so the $1 is written to the bash file?

Thanks

EDIT

This is the whole function:

    {
        $sPath = "minecraft/servers/".$user."/";
        $sSavingCode = "start.sh";
        $ssh->exec("cat > $sPath$sSavingCode <<EOF
screen -dmS $1 java -Xincgc -Xmx200M -jar craftbukkit-1.4.7.jar nogui
        ");
    }

$sPath and $sSavingCode are PHP variables, and the $1 is a bash variable that needs to be in the script.

Runner
  • 115
  • 2
  • 11

1 Answers1

3

Why not assigning your command to a simple variable?

    $command = ' screen -dmS \$1 java -Xincgc -Xmx200M -jar craftbukkit-1.4.7.jar nogui'

    $ssh->exec("cat > $sPath$sSavingCode <<EOF
$command
        ");
Th. Ma.
  • 9,432
  • 5
  • 31
  • 46
  • I'm assuming $sPath and $sSavingCode were declared in your PHP script, weren't they? Besides, is $1 actually supposed to be a shell variable? Could you please give a try to the snippet added to my original answer? – Th. Ma. Mar 31 '13 at 08:16
  • That code did not work, it creates the file, but does not print any text in it – Runner Mar 31 '13 at 12:44
  • Are you willing to obtain the first argument passed to your script using $1? If so, please consider using native PHP global variable $argv as shown in my updated codeblock. – Th. Ma. Mar 31 '13 at 13:46
  • I tried your code, and it creates the file still, but does not print any text to it. I also tried `$ssh->exec("cat > $sPath$sSavingCode < – Runner Mar 31 '13 at 13:54
  • 1
    I remove the first one which might be misleading then. Thanks. – Th. Ma. Mar 31 '13 at 15:46