I'm pretty close to my goal, but I am stuck at this point.
I'm trying to create an automation script that does some simple editing of the phpmyadmin config file.
cat /usr/share/phpmyadmin/config.sample.inc.php |sed s^//\ \$cfg\\[\'Servers\'^\$cfg\\[\'Servers\'^
Basically I'm trying to remove the // in all the lines that start with // $cfg['Servers']. The above line does indeed do that, but I'm unhappy with all the escaping that I had to do. I've tried hundreds of variations of this sed command, but escaping all those other characters seemed to be the only method that worked so far.
The other snag is: Eventually I want to pass the above command string through an elevated shell (using sudo sh -c), such as:
sudo sh -c "cat /usr/share/phpmyadmin/config.sample.inc.php |sed s^//\ \$cfg\\[\'Servers\'^\$cfg\\[\'Servers\'^ >/usr/share/phpmyadmin/config.inc.php"
but every time I try to do that, I get this error:
sed: -e expression #1, char 27: unterminated `s' command
So my question is: Can I simplify my sed expression such that I don't need to escape so many characters, and how do I pass this to an elevated shell so it doesn't break my sed s command?
I think my main issue is the the elevated shell is passed a string deliminated by double quotes and the sed string contains single quotes. In the past I generally didn't have commands that used both so I would be able to substitute one for the other.