我希望PHP等同于assigning value to shell variable using a function return value from Python
中给出的解决方案在我的php文件中,我读了一些像这样的常量值: -
$neededConstants = array("BASE_PATH","db_host","db_name","db_user","db_pass");
foreach($neededConstants as $each)
{
print constant($each);
}
到目前为止,在我的shell脚本中我有这个代码: -
function getConfigVals()
{
php $PWD'/developer.php'
//How to collect the constant values here??
#echo "done - "$PWD'/admin_back/developer/developer.php'
}
cd ..
PROJECT_ROOT=$PWD
cd developer
# func1 parameters: a b
getConfigVals
我能够正确地通过shell执行文件。
要进一步了解我要尝试的内容,请查看Cleanest way to read config settings from PHP file and upload entire project code using shell script
更新
已更正configs=getConfigVals
替换为getConfigVals
解决方案
正如Fritschy所回答的,它适用于这种修改: -
PHP代码 -
function getConfigVals()
{
php $PWD'/developer.php'
#return $collected
#echo "done - "$PWD'/admin_back/developer/developer.php'
}
shell代码 -
result=$(getConfigVals)
echo $result
答案 0 :(得分:3)
您必须执行该功能并将打印的内容分配给该变量:
configs=$(getConfigVals)
在扩展时查看该shell的联机帮助页以获取更多信息;)