如何将shell变量作为参数传递到PHP函数调用中?
我正在从命令行调用一个PHP脚本:如何将shell变量作为参数传递到PHP函数调用中?,php,shell,command-line-interface,Php,Shell,Command Line Interface,我正在从命令行调用一个PHP脚本: /usr/bin/php -r "require '/path/to/php/dummy.php'; echo getFunction(\"DummyParameter\")"; 调用的工作方式就像一个符咒,PHP函数返回正确的值。我想用$ShellVariable替换DummyParameter。当我替换DummyParameter时,它应该作为“$ShellVariable”字符串传递。以下是我尝试过的: /usr/bin/php -r "require
/usr/bin/php -r "require '/path/to/php/dummy.php'; echo getFunction(\"DummyParameter\")";
调用的工作方式就像一个符咒,PHP函数返回正确的值。我想用$ShellVariable
替换DummyParameter
。当我替换DummyParameter
时,它应该作为“$ShellVariable”
字符串传递。以下是我尝试过的:
/usr/bin/php -r "require '/path/to/php/dummy.php'; echo getFunction(\"$ShellVariable\")";
有没有办法将shell变量作为函数参数传递到PHP脚本中
提前感谢。传递CLI参数并使用数组,例如:
php -r 'printf("%s\n", $argv[1]);' "$(date)"
样本输出
您可能可以,但要获得正确的转义可能非常困难,并且需要相当混乱的代码。这是概念的证明吗?因为如果你只是把代码写在一个文件里,那就很简单了。
Tue Nov 29 14:09:07 +07 2016