Use bash variable in bash call to php function?
by buddy1234567 from LinuxQuestions.org on (#58H64)
Here is the situation:
I have a php script called testAddTwoNums-sol.php with a function called Calculator:
Code:<?php
//Add two numbers together
function Calculator($x, $y, $op) {
if($op == '+') {
$result = $x + $y;
}
}I'm attempting to pass values generated in bash to Calculator() like so:
Code:X=$[RANDOM%10+1]
Y=$[RANDOM%20+10]
# Addition
result=$(php -r "require 'testAddTwoNums-sol.php'; Calculator("X","Y",'+');")but it doesn't work. I get an error saying 'Warning: Use of undefined constant X - assumed 'X'
How can I pass X and Y from bash using the php cli (as I'm attempting to do above)?


I have a php script called testAddTwoNums-sol.php with a function called Calculator:
Code:<?php
//Add two numbers together
function Calculator($x, $y, $op) {
if($op == '+') {
$result = $x + $y;
}
}I'm attempting to pass values generated in bash to Calculator() like so:
Code:X=$[RANDOM%10+1]
Y=$[RANDOM%20+10]
# Addition
result=$(php -r "require 'testAddTwoNums-sol.php'; Calculator("X","Y",'+');")but it doesn't work. I get an error saying 'Warning: Use of undefined constant X - assumed 'X'
How can I pass X and Y from bash using the php cli (as I'm attempting to do above)?