Assigning Values ​​Printed by PHP CLI to Shell Variables

I want the PHP equivalent of the solution given in to assign the value of a shell variable using the return value of a function from Python

In my php file, I read some constant values, for example:

$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: -

 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 

I can execute the file through the shell correctly.

To read in more detail what I'm trying to do, check out The cleanest way to read configuration settings from a PHP file and load all project code using a shell script

Update

Fixed configs=getConfigVals replaced by getConfigVals

Decision

As Frici answered, he works with this modification: -

PHP code is

 function getConfigVals() { php $PWD'/developer.php' #return $collected #echo "done - "$PWD'/admin_back/developer/developer.php' } 

shell code -

 result=$(getConfigVals) echo $result 
+2
source share
1 answer

You need to execute the function and assign what is printed for this variable:

 configs=$(getConfigVals) 

See the man page for this shell for more;)

+3
source

Source: https://habr.com/ru/post/918183/


All Articles