Gentoo Archives: gentoo-user

From: Christoph Gysin <cgysin@×××.ch>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] sudo echo cannot write to /etc/ files ?
Date: Wed, 06 Jul 2005 15:37:56
Message-Id: 42CBF8A3.6050103@gmx.ch
In Reply to: Re: [gentoo-user] sudo echo cannot write to /etc/ files ? by David Morgan
1 David Morgan wrote:
2 > afaik you can only do it with su -c "echo foo >> bar", which stops bash
3 > from doing anything with the >> or the whitespace to begin with, but
4 > then passes everything inside the double quotes to another shell, which
5 > gets started by su -c
6 >
7 > It's kind of annoying, I know, but I don't think there's a way round it
8 > with sudo.
9
10 Yes it is possible. But you need the shell (which handles the redirect)
11 to run as root.
12
13 $ sudo echo package ~x86 >> /etc/portage/package.keywords
14
15 will run the redirection as user, where:
16
17 $ sudo bash -c "echo package ~x86 >> /etc/portage/package.keywords"
18
19 will run the redirection as root.
20
21 For stuff like this, I'd recommend you to write simple shell functions:
22
23 addkeyword(){
24 sudo bash -c "echo $* >> /etc/portage/package.keywords"
25 }
26
27 Write them in your .bashrc and their avaible when you need it.
28
29 Use it like this:
30
31 $ addkeyword package ~x86
32
33 Christoph
34 --
35 echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3
36 --
37 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] sudo echo cannot write to /etc/ files ? Holly Bostick <motub@××××××.nl>