0

I am trying to modify the line of a phpmyadmin configuration file, precisely, the file /etc/phpmyadmin/config.inc.php, in the line on the database server, where I need to change it with a bash instruction. I tried to do it with the sed and awk commands, but I still have no results.

The line that I want to modify is the following:

$cfg['Servers'][$i]['host'] = $dbserver;

For the following value:

$cfg['Servers'][$i]['host'] = '192.168.0.10';
Antonio Moreno
  • 881
  • 8
  • 9

1 Answers1

0
cat ini
"$cfg['Servers'][$i]['host'] = $dbserver;"

cat ini |  sed "s/\$dbserver/'192.168.0.10'/"
"$cfg['Servers'][$i]['host'] = '192.168.0.10';"

In other words, a

sed -i.bak-e "s/\$cfg\['Servers'\]\[\$i\]\['host'\] = \$dbserver;/\$cfg['Servers'][\$i]['host'] = '192.168.0.10';/" /etc/phpmyadmin/config.inc.php

should do the job. (with a .bak copy as a precaution).

tink
  • 14,342
  • 4
  • 46
  • 50
  • Thanks for the answer, the only thing that I detail and I know that I did not mention, is that the configuration file, uses many times those variables in different ways, therefore, it would modify all of them in the file, causing problems. The question is to escape the chain so that it can be replaced completely, since there is only one complete chain, just as I have shared it. – Antonio Moreno Nov 09 '18 at 05:15
  • 1
    Excellent response, it works very well. Only the last PHP variable (\$i) needs to escape. It is a pity that you do not have enough reputation to evaluate your response positively. Thank you! – Antonio Moreno Nov 09 '18 at 14:30
  • Right you are - edited. – tink Nov 09 '18 at 16:25