通过PHP CLI分配印值shell变量 [英] Assigning values printed by PHP CLI to shell variables
问题描述
我要的PHP相当于<特定的解决方案href=\"http://stackoverflow.com/questions/2115615/assigning-value-to-shell-variable-using-a-function-return-value-from-python\">assigning值外壳采用可变从Python中的函数的返回值
在我的PHP文件,我看了一些常数值如下: -
$ neededConstants =阵列(BASE_PATH,DB_HOST,DB_NAME,DB_USER,DB_PASS);
的foreach($ neededConstants每个$)
{
打印常数($个);
}
在我的shell脚本我有这个code到目前为止: -
函数getConfigVals()
{ PHP的$ PWD'/ developer.php //如何在这里收集的常数值?
#echo完成 - $ PWD'/ admin_back /开发商/ developer.php
}CD ..
PROJECT_ROOT = $ PWD
CD开发商#func1的参数:A B
getConfigVals
我能够通过外壳正确地执行该文件。
要什么,我试图做请检查<进一步阅读href=\"http://stackoverflow.com/questions/4374345/cleanest-way-to-read-config-settings-from-php-file-and-upload-entire-project-$c$c\">Cleanest办法从PHP文件中读取配置设置和使用shell脚本上传整个项目code
更新
修正 CONFIGS = getConfigVals
与 getConfigVals
解决方案
作为回答Fritschy,它的工作原理与此修改: -
PHP code -
函数getConfigVals()
{
PHP的$ PWD'/ developer.php
#return $收集
#echo完成 - $ PWD'/ admin_back /开发商/ developer.php
}
壳code -
的结果= $(getConfigVals)
回声$结果
您必须执行功能,并指定哪些打印到该变量:
CONFIGS = $(getConfigVals)
请参阅扩张,壳牌的更多的联机帮助页;)
I want the PHP equivalent of the solution given in assigning value to shell variable using a function return value from Python
In my php file, I read some constant values like this:-
$neededConstants = array("BASE_PATH","db_host","db_name","db_user","db_pass");
foreach($neededConstants as $each)
{
print constant($each);
}
And in my shell script I have this code so far:-
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
I am able to execute the file through shell correctly.
To read further on what I am trying to do please check Cleanest way to read config settings from PHP file and upload entire project code using shell script
Updates
Corrected configs=getConfigVals
replaced with getConfigVals
Solution
As answered by Fritschy, it works with this modification:-
PHP code -
function getConfigVals()
{
php $PWD'/developer.php'
#return $collected
#echo "done - "$PWD'/admin_back/developer/developer.php'
}
shell code -
result=$(getConfigVals)
echo $result
You have to execute the function and assign what is printed to that variable:
configs=$(getConfigVals)
See the manpage of that shell on expansion for more ;)
这篇关于通过PHP CLI分配印值shell变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!