将由PHP CLI输出的值分配给shellvariables

我想要使用Python的函数返回值给shell赋值的解决scheme的PHP等价物

在我的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: ab getConfigVals 

我能够通过正确的shell执行文件。

要进一步阅读我正在尝试做什么,请检查Cleanest方式从PHP文件中读取configuration设置,并使用shell脚本上传整个项目代码

更新

使用configs=getConfigValsreplace更正的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 

您必须执行该功能并将打印的内容分配给该变量:

 configs=$(getConfigVals) 

请参阅扩展的shell的联机帮助页面)