I'm trying to pass arguments back and forth, from shell to PHP, and back again. In my simple test, I'm getting easily from shell into PHP, but having no luck getting strings back out. I've tried both escapeshellarg and escapeshellcmd, but neither worked.
Shell
#!/bin/sh
# set a date and time variables, in the form of YYYY-MM-DD and HH:MM:SS
dateVar=`date +%Y-%m-%d`
timeVar=`date +%H_%M`
# Launching PHP
runPHP=`which php`
$runPHP calledPHP.php $timeVar $dateVar
# Returned from PHP
passTime=$1
echo "$passTime"
passDate=$2
echo "$passDate"
PHP
<?php
setlocale(LC_CTYPE, "en_US.UTF-8");
echo "PHP called.\n";
$logTime = $argv[1]."\n";
// echo $logTime;
$logDate = $argv[2]."\n";
// echo $logDate;
$passTime = escapeshellarg('Time: $logTime');
$passDate = escapeshellarg('Date: '.$logDate);
?>
Running the shell, the only echo that it get back is 'PHP called.' As you can see, I've tried two different syntaxes in the last two php variables. Neither seem to work. Is there a better function for this? Or, am I just using the wrong syntax?
Thanks in advance for any suggestions
php calledecho. And your$logTimeline is incorrect.'-quoted strings in PHP do NOT interpolate variables. your$passTimewill literally contain$,l,o,g, etc...$passDateand that looked correct to me, but I agree about the'-quoted string. I only tried it for completeness, because it was a "working example" that I found, although it obviously didn't work for me. I'm not really trying to get any output, per se, from the PHP, except for passing a string out of the PHP back to the encompassing shell script.