From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.43) id 1DqNWs-0004G2-Fc for garchives@archives.gentoo.org; Thu, 07 Jul 2005 03:58:26 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.13.4/8.13.4) with SMTP id j673ubPK000783; Thu, 7 Jul 2005 03:56:37 GMT Received: from mail.topcoder.com (mail.topcoder.com [63.144.135.218]) by robin.gentoo.org (8.13.4/8.13.4) with ESMTP id j673r7Ev001088 for ; Thu, 7 Jul 2005 03:53:08 GMT Received: from [192.168.63.62] ([216.84.5.97] RDNS failed) by mail.topcoder.com with Microsoft SMTPSVC(6.0.3790.211); Wed, 6 Jul 2005 23:54:05 -0400 Message-ID: <42CCA4BE.5000904@volumehost.com> Date: Wed, 06 Jul 2005 23:42:54 -0400 From: "Boyd Stephen Smith Jr." User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] sudo echo cannot write to /etc/ files ? References: <42CBE237.7050508@planet.nl> <200507061620.47943.gentoo@depardo.ch> <42CBF70B.4010703@planet.nl> In-Reply-To: <42CBF70B.4010703@planet.nl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 07 Jul 2005 03:54:05.0153 (UTC) FILETIME=[84F20510:01C582A7] X-Archives-Salt: accbe8de-5a2f-4dd6-a5dd-1dff14952a2e X-Archives-Hash: 0989931944085f3936a0584dee0dfd2d Holly Bostick wrote: > gentoo@depardo.ch schreef: >>I think the problem come from the fact that echo is sudo-ed but the shell >>redirection isn't. >> >>Compare this: >>su -c "echo foo > /etc/portage/whatever" >>and >>su -c "echo foo" > /etc/portage/whatever >> >>The first one will succeed, but not the second. > > Well, it didn't work (this to all the respondents). > > "sudo echo 'media-video/xine-ui ~x86' >>/etc/portage/package.keywords" This groups *everything* as one shell parameter, so it attempts to execute a file named "sudo echo 'media-video/xine-ui ~x86' >>/etc/portage/package.keywords" in your path. >>>/etc/portage/package.keywords: Onbekend bestand of map > ("unknown file or folder") Of course, since it's extremely unlikely a file with that name exists. > sudo echo 'media-video/xine-ui ~x86' >>/etc/portage/package.keywords Now, you've completely left out the quotes, so the redirection is done in the user shell, not the sudo shell. Of course, your user can't write to that file so you get: > -bash: /etc/portage/package.keywords: Toegang geweigerd > (permission refused) You want: sudo "echo 'media-video/xine-ui ~x86' >> /etc/portage/package.keywords" This cause the command echo 'media-video/xine-ui ~x86' >> /etc/portage/package.keywords to be passed to the sudo shell which causes the bash built-in: echo to be called with the single parameter media-video/xine-ui ~x86 and have it's output appended to the file /etc/portage/package.keywords > I'm really lost. Where am I going wrong? You simply aren't being careful enough with you quotes and misunderstanding the intricacies of shell expansion and nesting. > Oh, btw, just remembered-- this is bash 3. Does that make a difference? No. -- Boyd Stephen Smith Jr. bss03@volumehost.com -- gentoo-user@gentoo.org mailing list