Gentoo Archives: gentoo-user

From: Holly Bostick <motub@××××××.nl>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] sudo echo cannot write to /etc/ files ?
Date: Wed, 06 Jul 2005 16:16:11
Message-Id: 42CC01C5.10905@planet.nl
In Reply to: Re: [gentoo-user] sudo echo cannot write to /etc/ files ? by Christoph Gysin
1 Christoph Gysin schreef:
2 > David Morgan wrote:
3 >
4 >>afaik you can only do it with su -c "echo foo >> bar", which stops bash
5 >>from doing anything with the >> or the whitespace to begin with, but
6 >>then passes everything inside the double quotes to another shell, which
7 >>gets started by su -c
8 >>
9 >>It's kind of annoying, I know, but I don't think there's a way round it
10 >>with sudo.
11 >
12 >
13 > Yes it is possible. But you need the shell (which handles the redirect)
14 > to run as root.
15
16 Ah-HAH! (at least I figured that much out, thanks for confirming)
17
18 >
19 > $ sudo echo package ~x86 >> /etc/portage/package.keywords
20 >
21 > will run the redirection as user, where:
22 >
23 > $ sudo bash -c "echo package ~x86 >> /etc/portage/package.keywords"
24 >
25 > will run the redirection as root.
26 >
27 > For stuff like this, I'd recommend you to write simple shell functions:
28 >
29 > addkeyword(){
30 > sudo bash -c "echo $* >> /etc/portage/package.keywords"
31 > }
32 >
33 > Write them in your .bashrc and their avaible when you need it.
34 >
35 > Use it like this:
36 >
37 > $ addkeyword package ~x86
38 >
39 > Christoph
40
41 Thank you, Christoph!!!!
42
43 You have not only saved my sanity, but you've given me a solution to two
44 problems you didn't even know I had (it was the next question)! i.e.,
45 how to essentially export self-created variables or something similar
46 (you don't know how many times I've put a comma between package and
47 keywords/use/unmask, and I really needed some way to not have to be
48 typing it all the time until I get more time in with GTypist); and also
49 how to easily use some of the aliases I've got in root's .bashrc (or at
50 least their functionality). Now, with some minor adjustments of this
51 template, not only can I add keywords (or useflags or mask and unmask)
52 easily, I can also open the package.* file in nano and edit it easily if
53 I screw up, or want to check something.
54
55 Last question on this subject-- is this all just bash scripting (so I
56 can learn about it if I sit and study the abs-guide) or is there
57 someplace else I should check out if I want to learn how to write this
58 stuff myself?
59
60 Thanks again,
61 Holly
62
63
64
65 --
66 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] sudo echo cannot write to /etc/ files ? Christoph Gysin <cgysin@×××.ch>
Re: [gentoo-user] sudo echo cannot write to /etc/ files ? Richard Fish <bigfish@××××××××××.org>