If you express your command without single quotes, you can put it inside single quotes and execute that via an intermediate shell.
To execute this as root:
echo 'clock_hctosys="YES"' >> /etc/conf.d/hwclock
Write the command a different way that doesn't use
echo clock_hctosys=\"YES\" >> /etc/conf.d/hwclock
sudo sh -c …:
sudo sh -c 'echo clock_hctosys=\"YES\" >> /etc/conf.d/hwclock'
Alternatively, to write output to a file that only root can write to, call
sudo tee. Pass the
-a option to
tee to append to the destination file, otherwise the file is truncated.
echo 'clock_hctosys="YES"' | sudo tee -a /etc/conf.d/hwclock >/dev/null
For more complex file modifications, you can call
sudo perl, …
Alternatively, use a decent editor and make it call sudo. In Emacs, open
/sudo:/etc/conf.d/hwclock. In Vim, call
:w !sudo tee % to write to the opened file as root, or use the sudo.vim plugin. Or go from the sudo end and call
Or you can give in to the dark side and run a shell as root.
$ sudo -i
# echo 'clock_hctosys="YES"' >> /etc/conf.d/hwclock