I want to add lines to /etc/my.conf as "sudo" using Shell.
Without logging as sudo, I can do:
{ echo "[mysqld]"
echo "default-character-set=utf8"
echo "character_set_server=utf8"
echo "[mysql]"
echo "default-character-set=utf8"
} >> /etc/my.conf
But when:
sudo { echo "[mysqld]"
echo "default-character-set=utf8"
echo "character_set_server=utf8"
echo "[mysql]"
echo "default-character-set=utf8"
} >> /etc/my.conf
I get an error:
sudo: {: command not found
character_set_server=utf8
[mysql]
default-character-set=utf8 .....
What am I doing wrong?
{
is not a command, but an element of shell syntax.sudo
takes commands, not shell script. The general solution to this kind of problem is to usesh -c
; that lets you make a command whose only operation is to run a little piece of script.