coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tee: add a -q/--quiet option


From: Pádraig Brady
Subject: Re: [PATCH] tee: add a -q/--quiet option
Date: Sat, 26 Dec 2020 13:55:14 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0

On 24/12/2020 06:01, Alex Henrie wrote:
---
It is very useful to be able to read a file as root and then process it
as an ordinary user, for example:

sudo cat protected.txt | grep foo

However, there is currently no exact equivalent for the opposite:
Generating text as a normal user and writing it to a file as root. `tee`
is commonly used for this purpose:

echo foo | sudo tee protected.txt

The downside is that tee always prints to standard output in addition to
writing to the file. This can be avoided with piping, but it makes the
command quite cumbersome:

echo foo | sudo tee protected.txt > /dev/null

I propose adding a -q/--quiet flag to `tee` which causes it to only
write to the specified files and not to stdout. This would allow the
following convenient command to be used for writing to a protected file:

echo foo | sudo tee -q protected.txt

This would be a GNU extension. Happy holidays!

Thanks for the suggestion. It has some merit.
I wouldn't count the shorter syntax, but it would be
better to avoid the redundant write to stdout.
However I'm not sure it's worth adding the incompatibility
(for scripts running with other (older) implementations of tee,
only for performance reasons.  Also the perf improvement
isn't that significant, and it's not for the main usage pattern.

Therefore I'd be 60:40 against adding this.

thanks,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]