echo bug?

Karl Auer kauer at biplane.com.au
Sat Sep 12 16:58:36 UTC 2009


On Sat, 2009-09-12 at 11:24 -0300, Derek Broughton wrote:
> >>> Appears he's trying an easy way to add a line to an apt-repo file.

I've lost track of the OP, but someone wanted to use redirection on a
sudo command line to append text to a root-owned file. He/she discovered
that the redirection applied in the user session, not the sudo session.

A very simple script solves this, let's call it acat for "appending
cat". It contains these lines, and is owned by the user:

   #!/bin/sh
   cat >> $1

Now you can do this:

   echo blah | sudo acat some_file

... and "blah" will be appended to some_file, even though it is owned by
root.

It's not as flexible as using redirection directly on the command line,
but it's not too bad for the odd occasion, or for some regular task you
need to do.

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)                   +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/                  +61-428-957160 (mob)

GPG fingerprint: 07F3 1DF9 9D45 8BCD 7DD5 00CE 4A44 6A03 F43A 7DEF

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20090913/465e7759/attachment.sig>


More information about the ubuntu-users mailing list