I want to replace in /usr/share/phpmyadmin/config.inc.php file
$cfg['blowfish_secret'] = '';
to
$cfg['blowfish_secret'] = 'blablabla';
with sed.
I am trying this:
sed -i "s/$cfg['blowfish_secret'] = '';/$cfg['blowfish_secret'] = 'blablabla';/g" /usr/share/phpmyadmin/config.inc.php
but it doesn’t change. How can I do this?
2
Answers
You need to do some more escaping:
Since your command is in double quotes to accommodate the single-quoted strings in the data, you will need to escape both dollar signs so that
$cfg
doesn’t get interpreted as a variable by the shell.You need to escape the square brackets on the left hand side so the enclosed string isn’t treated as a bracket expression (group of characters to match) by
sed
.This might work for you (GNU sed):
This is a good example of:
For the third problem; most people (it seems) prefer to surround the whole of the sed command by double quotes. This solves the problem of single quotes but opens up a side effect that the command can be interpreted by the shell. If you are sure that these side effects will not rear their ugly head (variables and shell history can catch one out) go ahead, but by surrounding the sed command by single quotes and:
'''
before any literal
[
,]
,*
,^
,$
andwill most likely, save the day.