Fwd: [PATCH] tee: Add -q, --quiet option to not write to stdout
From:
Alejandro Colomar (mailing lists)
Subject:
Fwd: [PATCH] tee: Add -q, --quiet option to not write to stdout
Date:
Thu, 21 Jan 2021 14:49:24 +0100
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1
Hi all,
I don't know if my patch (which I sent from my other email account)
arrived to the list (as that account is not subscribed to the list).
Please find it below anyway.
Regards,
Alex
-------- Forwarded Message --------
Subject: [PATCH] tee: Add -q, --quiet option to not write to stdout
Date: Thu, 21 Jan 2021 14:17:36 +0100
From: Alejandro Colomar <alx.manpages@gmail.com>
To: coreutils@gnu.org
CC: Alejandro Colomar <alx.manpages@gmail.com>
This is useful for using tee to just write to a file,
at the end of a pipeline,
without having to redirect to /dev/null
Example:
echo 'foo' | sudo tee -q /etc/foo;
is equivalent to the old (and ugly)
echo 'foo' | sudo tee /etc/foo >/dev/null;
....
Testing:
$echo 'foo' | ./src/tee -q bar;
$cat bar;
foo
$echo 'fu' | ./src/tee --quiet baz;
$cat baz;
fu
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---
Hi all,
I really don't know why this hasn't been done yet...
It's quite ugly to have to redirect to /dev/null,
and running a new shell (or similar) to allow using '>' as root
isn't nice either.
Please note that 'make check' did return 1 FAIL,
but I'm not very familiar with your building system,
and it didn't look like related to tee.c, so I ignored it.
My own tests (see the commit msg above), did work.
I also had some problems with your commit-msg git hook,
which I had to remove to be able to commit.
Regards,
Alex
src/tee.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..5de997357 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -45,6 +45,9 @@ static bool append;
/* If true, ignore interrupts. */
static bool ignore_interrupts;
+/* Don't write to stdout */
+static bool quiet;
+
enum output_error
{
output_error_sigpipe, /* traditional behavior, sigpipe
enabled. */
{
switch (optc)
{
@@ -151,6 +157,10 @@ main (int argc, char **argv)
output_error = output_error_warn_nopipe;
break;
+ case 'q':
+ quiet = true;
+ break;
+
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -235,8 +245,9 @@ tee_files (int nfiles, char **files)
break;
/* Write to all NFILES + 1 descriptors.
- Standard output is the first one. */
- for (i = 0; i <= nfiles; i++)
+ Standard output is the first one.
+ If 'quiet' is true, write to descriptors 1 and above (omit
stdout) */
+ for (i = quiet; i <= nfiles; i++)
if (descriptors[i]
&& fwrite (buffer, bytes_read, 1, descriptors[i]) != 1)
{
--
2.30.0