Gentoo Archives: gentoo-user

From: David Morgan <david.morgan@××××××××××××××××.uk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] sudo echo cannot write to /etc/ files ?
Date: Wed, 06 Jul 2005 15:17:09
Message-Id: 20050706151218.GA19645@valinor.dynalias.net
In Reply to: Re: [gentoo-user] sudo echo cannot write to /etc/ files ? by Holly Bostick
1 On 16:54 Wed 06 Jul , Holly Bostick wrote:
2 > OK, you all likely realize that I responded before I had got the three
3 > more messages telling me what to do.
4 >
5 > I'm sure it will work (three people telling you the exact same thing is
6 > pretty convincing ;-) ), but what I don't understand is why/how, if I
7 > want to
8 >
9 > sudo echo 'media-video/xine-ui ~x86' >>/etc/portage/package.keywords
10 >
11 > changing that to
12 >
13 > "sudo echo media-video/xine-ui ~x86 >>/etc/portage/package.keywords"
14 >
15 > is going to write the line
16 >
17 > media-video/xine-ui ~x86
18 >
19 > to /etc/portage/package.keywords-- i.e., why are the internal quotes no
20 > longer necessary?
21 >
22 > Or should it be
23 >
24 > "sudo echo 'media-video/xine-ui ~x86' >>/etc/portage/package.keywords"
25 >
26 > or will that *really* screw everything up?
27 >
28 > (As you see, my understanding of bash is trying to improve, with only
29 > very limited success :-) ).
30 >
31
32 Nope, I don't think you can do it with sudo since bash uses whitespace
33 as a separator, so if you do sudo "echo foo >> bar", it'll look for a
34 single command "echo foo >> bar", which is not what you want - you want
35 a command echo with argument foo, and then redirect the output to bar
36 (the double quotes prevent bash from evaluating the whitespace or the
37 >>).
38
39 afaik you can only do it with su -c "echo foo >> bar", which stops bash
40 from doing anything with the >> or the whitespace to begin with, but
41 then passes everything inside the double quotes to another shell, which
42 gets started by su -c
43
44 It's kind of annoying, I know, but I don't think there's a way round it
45 with sudo.
46
47 Dave
48
49 --
50 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] sudo echo cannot write to /etc/ files ? Neil Bothwick <neil@××××××××××.uk>
Re: [gentoo-user] sudo echo cannot write to /etc/ files ? Christoph Gysin <cgysin@×××.ch>