On Thu, Nov 21, 2024 at 08:32:30AM +0000, Michael Kjörling wrote:
> On 20 Nov 2024 17:49 -0500, from g...@wooledge.org (Greg Wooledge):
> >> sudo echo "something" >>/etc/postfix/virtual_alias_maps
> > 
> >> Can you help me why the first sudo failed?
> > 
> > The redirection >> is being done before sudo is executed.
> 
> Indeed.
> 
> The usual pattern if you need to do this in a non-root-only script is
> to do something like `echo | sudo tee` to tie the sudo to the thing
> that needs write access to the output file.

My favourite is actually "sudo dd of=<file>" it hasn't the side effect
of flooding your stdout (esp. with a larger, uglier thing).

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature

Reply via email to