I am trying to read some variables from a php config file using bash & it is working for the most part, but I am having issues trying to use the values passed back.
The variuable is found in config, but when it is passed back it still has the single or double quotes from PHP around it.
Here is what I am using.
DBPASS="$(grep -oE '\$database_password = .*;' $CONFIG | tail -1 | sed 's/$database_password = //g;s/;//g')"
now, the variables may be wrapped in either single or double quotes AND a single quote may be present in a password field. So I can't just strip all of them out.
any idea how to do this?
UPDATE
So going another way with this, I have added a bit to the bash script (which basically backs up a CMS) that will look for and write a little PHP "helper". That helper will just read the config, build an array & pass it back to the bash script.
HELPER="backup-helper.php";
CONFIG="../core/config/config.inc.php"
if [ ! -f "$HELPER" ]; then
echo '<?php' >> $HELPER;
echo '$config = "$argv[1]";' >> $HELPER;
echo 'include_once($config);' >> $HELPER;
echo 'echo $dbase;' >> $HELPER;
echo 'echo $modx_core_path;' >> $HELPER;
echo 'return "this";' >> $HELPER;
chmod 755 $HELPER;
php $HELPER $CONFIG;
fi
So this is basically just looking for the helper files & creating it if it does not exist, then runs it to test - this all works.
I can easily add the logic to create an array of what I need from the config file, but:
how do I format it (the array to be passed back) so that bash will understand it? how do I pass it (the array) back to bash? (basically how do I tell bash to expect a return value?)