Mailinglist Archive: opensuse (1445 mails)

< Previous Next >
Re: [opensuse] bash - howto sudo echo X >> Y (sed?)
On 03/11/2012 01:27 PM, David C. Rankin wrote:
Guys,

I have an interesting question. I have a file that I need to append
information to that is owned by root. Initially I wanted to use echo:

sudo echo "X" >> y.txt

But, of course the echo has root privileges, but the redirection does not.
So
then I though about sed. It works, but how do I tell sed to 'append to end of
file'?

The last word in the existing file is custompkgs, but that isn't guaranteed
to
stay that way. As it sits, I can:

sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#'
$CHROOT/root/etc/repo.conf

How can I omit searching for a word and just tell sed to append at end of
file?

Or, how can I use echo or cat to do the same thing, but overcome the lack of
privilege on the >> ?

sudo bash -c "echo testing >>/root/test"

The answer is in "man sudo"

Regards,
Jim Cunning

--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
References