Say I have a file (php as it happens), with a number of variable declarations:
$dbuser = 'fred';
$dppass = 'abc123';
$dhhost = '127.0.0.1';
What I want to do from a BASH script, is parse this file, identify the variables I need, and read their values into variables I can access from my BASH script.
Obviously, the above file being PHP, has other lines that I'm not interested in.
I can extract the info I need from the bash shell using the following command:
grep \$dbuser config.php.inc | grep -Po "\'.*\'" | cut -d \' -f 2
which neatly returns
fred
But when I try to add this to a bash script to put the output into a variable using backticks, as follows:
dbuser=`grep \$dbuser config.php.inc | grep -Po "\'.*\'" | cut -d \' -f 2`
my BASH script hangs at this point.
Why is this hanging, or, is there a better way of doing what I'm trying to achieve?