Re: [PATCH] tee: Add -q, --quiet option to not write to stdout

Started by Alejandro Colomar (man-pages) on Jan 21, 2021 · 19 messages from 7 authors · Last reply Mar 15, 2021

open the first message on its own page

  1. [PATCH v2] tee: Add -q, --quiet, --silent option to not write to stdout
    Related patches
  2. [PATCH] tee: Add -q, --quiet, --silent option to not write to stdout
    Related patches
  3. [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
    Related patches
Message details and related content
[CC += mtk, linux-api, freebsd, openbsd]

On 1/21/21 10:26 PM, Alejandro Colomar (man-pages) wrote:
Hi Berny,

On 1/21/21 10:01 PM, Bernhard Voelker wrote:
quoted
On 1/21/21 7:39 PM, Alex Henrie wrote:
quoted
That said, I would love to see `tee -q` added to a future revision of
POSIX and adopted everywhere.
I like the idea.
We have been living for decades without a terminating "pipe end piece",
so why hurrying a new option into an implementation of 'tee'?
Instead, this could be discussed thoroughly and specified by the OpenGroup
and nailed down in a new POSIX issue, and then all implementations
could adopt it consistently.
Are you willing to start the discussion there?
Hi Berny,

Please don't feel like I'm hurrying with this.
I'm strongly defending my patch to try to
convince you that it's a Good Thing :-)
But if it has to undergo a long discussion
with POSIX, BSD, and whoever, that's fine by me.

I'll send a v2 with --silent in a moment.


Hi Michael,

Talking about designing new APIs,
you might have something to say here,
even if it's not for the kernel.


I also CCd a few lists that might be interested.
Please comment.


Cheers,

Alex
I am.  However, the Austing Group is a nightmare in terms of login,
and doing things requiring an account; at least for me.

I'd prefer that someone else opens a bug there and links to the
discussion on an open mailing list like this one.

Do they have an open mailing list?

Is anyone hepling me report the bug to them?  I should learn at this
point...
quoted
BTW: --quiet is usually used to avoid outputting of informational
messages (e.g. wget, head, tail, md5sum), while 'tee' would change
its functional behavior.
Maybe --drain, --drain-stdout, --discard-stdout (-d), --no-stdout (-n),
--elide-stdout (-e) or something similar would be more appropriate?
I stand by -q, --quiet.  Conforming to: grep. Maybe there's some other.

$ man grep 2>/dev/null | sed -n '/-q, --quiet, --silent/,/^$/p'
       -q, --quiet, --silent
              Quiet;  do  not  write  anything to standard output.
              Exit immediately with zero status if  any  match  is
              found,  even if an error was detected.  Also see the
              -s or --no-messages option.


quoted
Have a nice day,
Berny
Kind regards,

Alex

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

[PATCH v2] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
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;

Tools with a similar interface: grep

Signed-off-by: Alejandro Colomar <redacted>
---

v2: Add --silent synonym to --quiet, per GNU guidelines.
    I tested tee --silent with success.

 src/tee.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..68ace983a 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.  */
@@ -61,6 +64,8 @@ static struct option const long_options[] =
   {"append", no_argument, NULL, 'a'},
   {"ignore-interrupts", no_argument, NULL, 'i'},
   {"output-error", optional_argument, NULL, 'p'},
+  {"quiet", no_argument, NULL, 'q'},
+  {"silent", no_argument, NULL, 'q'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -93,6 +98,7 @@ Copy standard input to each FILE, and also to standard output.\n\
 "), stdout);
       fputs (_("\
   -p                        diagnose errors writing to non pipes\n\
+  -q, --quiet, --silent     don't write to standard output\n\
       --output-error[=MODE]   set behavior on write error.  See MODE below\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -130,6 +136,7 @@ main (int argc, char **argv)
 
   append = false;
   ignore_interrupts = false;
+  quiet = false;
 
   while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) != -1)
     {
@@ -151,6 +158,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 +246,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

Re: [PATCH v2] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
I added a few FreeBSD CCs that I found on their tee.c's git blame, because the freebsd list rejects external mail.

Please have a look at the proposal below, and the discussion that started on gnu coreutil's list.

On 1/22/21 12:12 AM, Alejandro Colomar wrote:
quoted hunk
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;

Tools with a similar interface: grep

Signed-off-by: Alejandro Colomar <redacted>
---

v2: Add --silent synonym to --quiet, per GNU guidelines.
     I tested tee --silent with success.

  src/tee.c | 16 ++++++++++++++--
  1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..68ace983a 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.  */
@@ -61,6 +64,8 @@ static struct option const long_options[] =
    {"append", no_argument, NULL, 'a'},
    {"ignore-interrupts", no_argument, NULL, 'i'},
    {"output-error", optional_argument, NULL, 'p'},
+  {"quiet", no_argument, NULL, 'q'},
+  {"silent", no_argument, NULL, 'q'},

43 more quoted lines


-- 
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

[PATCH] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
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;
---

v2: Add --silent synonym to --quiet, per GNU guidelines.
    I tested --silent with success.

v3: Added -q to opstring, which I removed by accident in v2.
    I tested all -q, --quiet and --silent this time.


 src/tee.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..1dfa92cf2 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.  */
@@ -61,6 +64,8 @@ static struct option const long_options[] =
   {"append", no_argument, NULL, 'a'},
   {"ignore-interrupts", no_argument, NULL, 'i'},
   {"output-error", optional_argument, NULL, 'p'},
+  {"quiet", no_argument, NULL, 'q'},
+  {"silent", no_argument, NULL, 'q'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -93,6 +98,7 @@ Copy standard input to each FILE, and also to standard output.\n\
 "), stdout);
       fputs (_("\
   -p                        diagnose errors writing to non pipes\n\
+  -q, --quiet, --silent     don't write to standard output\n\
       --output-error[=MODE]   set behavior on write error.  See MODE below\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -130,8 +136,9 @@ main (int argc, char **argv)
 
   append = false;
   ignore_interrupts = false;
+  quiet = false;
 
-  while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "aipq", long_options, NULL)) != -1)
     {
       switch (optc)
         {
@@ -151,6 +158,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 +246,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

[PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
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;

Signed-off-by: Alejandro Colomar <redacted>
---

Resend as v3. I forgot to change the subject line.
Everything else is the same as in
[off-list ref].

 src/tee.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..1dfa92cf2 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.  */
@@ -61,6 +64,8 @@ static struct option const long_options[] =
   {"append", no_argument, NULL, 'a'},
   {"ignore-interrupts", no_argument, NULL, 'i'},
   {"output-error", optional_argument, NULL, 'p'},
+  {"quiet", no_argument, NULL, 'q'},
+  {"silent", no_argument, NULL, 'q'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -93,6 +98,7 @@ Copy standard input to each FILE, and also to standard output.\n\
 "), stdout);
       fputs (_("\
   -p                        diagnose errors writing to non pipes\n\
+  -q, --quiet, --silent     don't write to standard output\n\
       --output-error[=MODE]   set behavior on write error.  See MODE below\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -130,8 +136,9 @@ main (int argc, char **argv)
 
   append = false;
   ignore_interrupts = false;
+  quiet = false;
 
-  while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "aipq", long_options, NULL)) != -1)
     {
       switch (optc)
         {
@@ -151,6 +158,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 +246,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

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On 1/24/21 5:11 PM, Teran McKinney wrote:
On 2021-01-24 13-18-46    , Alejandro Colomar wrote:
quoted
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;

Signed-off-by: Alejandro Colomar <redacted>
---
[...]
Hi,

Why is this a thing?

The point of tee is to write a file *and* to stdout. If you don't want use that, use:

`> file`

To overwrite.

Or

`>> file`

To append.

I guess the only reason this would be used is if you wanted to write
multiple files at the same time, which tee supports.

-Teran

Hi Teran,

The rationale is that protected files can't be modified with '>', unless
you give superuser rights to the whole shell.  If you want fine-grained
control over the rights of the tools in the pipeline, you'll come to
times where you want the write step to be the only one to have those,
and you can't [sudo >] nor [sudo >>], which by the way I would consider
an even better solution, but which would require much more work, and
designing a completely new idiom for it, which would face much more
objection too.

Regards,

Alex

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On 2021-01-24 13-18-46    , Alejandro Colomar wrote:
quoted hunk
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;

Signed-off-by: Alejandro Colomar <redacted>
---

Resend as v3. I forgot to change the subject line.
Everything else is the same as in
[off-list ref].

 src/tee.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..1dfa92cf2 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.  */
@@ -61,6 +64,8 @@ static struct option const long_options[] =
   {"append", no_argument, NULL, 'a'},
   {"ignore-interrupts", no_argument, NULL, 'i'},
   {"output-error", optional_argument, NULL, 'p'},

54 more quoted lines

Hi,

Why is this a thing?

The point of tee is to write a file *and* to stdout. If you don't want use that, use:

`> file`

To overwrite.

Or

`>> file`

To append.

I guess the only reason this would be used is if you wanted to write
multiple files at the same time, which tee supports.

-Teran

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On Sun, Jan 24, 2021 at 01:18:46PM +0100, Alejandro Colomar wrote:
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)
You keep repeating "ugly" as the reason you are wanting this.

I consider adding special options to command to solve an imagined
issue that can be solved with a general concept like redirection ugly.
Please stop pushing your diff to this list. So far nobody showed any
interest.

	-Otto
quoted hunk
echo 'foo' | sudo tee /etc/foo >/dev/null;

Signed-off-by: Alejandro Colomar <redacted>
---

Resend as v3. I forgot to change the subject line.
Everything else is the same as in
[off-list ref].

 src/tee.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index c81faea91..1dfa92cf2 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.  */
@@ -61,6 +64,8 @@ static struct option const long_options[] =
   {"append", no_argument, NULL, 'a'},
   {"ignore-interrupts", no_argument, NULL, 'i'},
   {"output-error", optional_argument, NULL, 'p'},
+  {"quiet", no_argument, NULL, 'q'},
+  {"silent", no_argument, NULL, 'q'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -93,6 +98,7 @@ Copy standard input to each FILE, and also to standard output.\n\
 "), stdout);
       fputs (_("\
   -p                        diagnose errors writing to non pipes\n\

41 more quoted lines

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
Otto Moerbeek [off-list ref] wrote:
On Sun, Jan 24, 2021 at 01:18:46PM +0100, Alejandro Colomar wrote:
quoted
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)
You keep repeating "ugly" as the reason you are wanting this.

I consider adding special options to command to solve an imagined
issue that can be solved with a general concept like redirection ugly.
Please stop pushing your diff to this list. So far nobody showed any
interest.
I also see ZERO reason for this change.

This change will encourage the creation of non-portable scripts, which
harms backwards compatibility and portability, while increasing the
cognitive cost of building software in a simple and useable command
ecosystem.

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On Sun, Jan 24, 2021 at 10:51 AM Otto Moerbeek [off-list ref] wrote:
Please stop pushing your diff to this list. So far nobody showed any
interest.
I am definitely interested. Bernhard Voelker seemed to express
interest as well, conditional on -q being added to POSIX first.[1]
Also, a --quiet flag was proposed back in 2001 by Roman Czyborra [2]
and Jim Meyering expressed support for the idea.[3]

-Alex

[1] https://lists.gnu.org/archive/html/coreutils/2021-01/msg00043.html
[2] https://lists.gnu.org/archive/html/bug-sh-utils/2001-05/msg00024.html
[3] https://lists.gnu.org/archive/html/bug-sh-utils/2001-05/msg00039.html

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On Sun, Jan 24, 2021 at 01:01:45PM -0700, Alex Henrie wrote:
On Sun, Jan 24, 2021 at 10:51 AM Otto Moerbeek [off-list ref] wrote:
quoted
Please stop pushing your diff to this list. So far nobody showed any
interest.
I am definitely interested. Bernhard Voelker seemed to express
interest as well, conditional on -q being added to POSIX first.[1]
Also, a --quiet flag was proposed back in 2001 by Roman Czyborra [2]
and Jim Meyering expressed support for the idea.[3]

-Alex

[1] https://lists.gnu.org/archive/html/coreutils/2021-01/msg00043.html
[2] https://lists.gnu.org/archive/html/bug-sh-utils/2001-05/msg00024.html
[3] https://lists.gnu.org/archive/html/bug-sh-utils/2001-05/msg00039.html
"This list" is the OpenBSD tech list, sorry I did leave out this
context info.

	-Otto

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On 1/24/21 9:01 PM, Alex Henrie wrote:
I am definitely interested. Bernhard Voelker seemed to express
interest as well, conditional on -q being added to POSIX first.[1]
Just to clarify: I'm not as enthusiastic to add that option as it
may have sounded.

Let me put it like this: if -q once gets standardized by POSIX,
then we'd take it over in the GNU tee implementation.

Let me summarize so far:
The suggestion is to solve the problem to save some data coming from
a pipe as a different user.
There are at least those known solutions:
  - use > or >> redirection.
  - use dd(1)

I have the impression that a home for this feature was searched
in any tool, and as tee(1) already knew how to write to a file,
had the "append" feature, and is often used in pipes, it was
tempting to add it there.

But looking deeper, --quiet doesn't seem to fit well into 'tee'.
It even contradicts to the title line in the man page:
  "read from standard input and write to standard output and files"

An off-tech argument: ask a local plumber if he'd would ever use
a tee piece instead of a pipe end piece.  I guess he would only
if he wouldn't have anything else at hand.

A word to the proposed patch: what should happen, if the user does
not give a file?
  A | B | tee -q
The patch just silently ignored that situation which feels wrong.

Therefore, adding a feature which does not really fit is wrong, and
contradicts the one-tool-for-one-purpose UNIX philosophy.

OTOH I understand that there's a little gap in the tool landscape.
Astonishingly, there doesn't seem to exist a trivial tool to redirect
from standard input (or any other input file descriptor) to a file.
I wrote such a little tool in the attached:

29 more lines

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
Am 24.01.2021 um 13:18 schrieb Alejandro Colomar:
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;
Why don't you just do

echo foo > /etc/foo

or

sudo sh -c 'echo foo > /etc/foo' ?

I don't normally use sudo, so there might be some better way of using it.

Kind regards,
Philipp

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
Hi Berny,

On 1/25/21 12:33 PM, Alejandro Colomar (man-pages) wrote:
On 1/25/21 5:03 AM, Bernhard Voelker wrote:
quoted
On 1/24/21 9:01 PM, Alex Henrie wrote:
quoted
I am definitely interested. Bernhard Voelker seemed to express
interest as well, conditional on -q being added to POSIX first.[1]
Just to clarify: I'm not as enthusiastic to add that option as it
may have sounded.

Let me put it like this: if -q once gets standardized by POSIX,
then we'd take it over in the GNU tee implementation.

Let me summarize so far:
The suggestion is to solve the problem to save some data coming from
a pipe as a different user.
There are at least those known solutions:
   - use > or >> redirection.
   - use dd(1)

I have the impression that a home for this feature was searched
in any tool, and as tee(1) already knew how to write to a file,
had the "append" feature, and is often used in pipes, it was
tempting to add it there.

But looking deeper, --quiet doesn't seem to fit well into 'tee'.
It even contradicts to the title line in the man page:
   "read from standard input and write to standard output and files"

An off-tech argument: ask a local plumber if he'd would ever use
a tee piece instead of a pipe end piece.  I guess he would only
if he wouldn't have anything else at hand.
I never knew what 'tee' meant.  That makes sense now.
quoted
A word to the proposed patch: what should happen, if the user does
not give a file?
   A | B | tee -q
The patch just silently ignored that situation which feels wrong.

Therefore, adding a feature which does not really fit is wrong, and

19 more quoted lines


On second thought, this program does two things: read any FD, and write to file.  I think it should be limited to writing to a file from stdin.

If you think there's a need for reading FDs other than 0, you might as well want to pipe that information you're reading from them to filter it with another tool, and this program doesn't allow you to do that, as it's a sink.

So, I would remove '-i, --input-stream'.  (And if you think it's missing, maybe write a program to read from any FD and write to stdout.)

Regards,

Alex

quoted
   The default input stream number FD is 0, representing the standard input.

This allows not only to copy data from standard input, but from any
file descriptor open for reading.  It also allows control over
how the output file will be opened (e.g. with O_CREAT|E_EXCL).

The OPs case would look like:

   echo 'foo' | sudo sink /etc/foo
or
   echo 'foo' | sudo sink -a /etc/foo  # append.
or
   echo 'foo' | sudo sink -c /etc/foo  # ensure creation of the file.

I'm not sure if this will ever be considered for inclusion -
I just did it "for fun". ;-)
Tested-by: Alejandro Colomar <redacted>
Reviewed-by: Alejandro Colomar <redacted>

Much better than my patch.  :-)
quoted
Have a nice day,
Berny
Have a nice day!
Alex


-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

-- 
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On 1/25/21 5:03 AM, Bernhard Voelker wrote:
On 1/24/21 9:01 PM, Alex Henrie wrote:
quoted
I am definitely interested. Bernhard Voelker seemed to express
interest as well, conditional on -q being added to POSIX first.[1]
Just to clarify: I'm not as enthusiastic to add that option as it
may have sounded.

Let me put it like this: if -q once gets standardized by POSIX,
then we'd take it over in the GNU tee implementation.

Let me summarize so far:
The suggestion is to solve the problem to save some data coming from
a pipe as a different user.
There are at least those known solutions:
   - use > or >> redirection.
   - use dd(1)

I have the impression that a home for this feature was searched
in any tool, and as tee(1) already knew how to write to a file,
had the "append" feature, and is often used in pipes, it was
tempting to add it there.

But looking deeper, --quiet doesn't seem to fit well into 'tee'.
It even contradicts to the title line in the man page:
   "read from standard input and write to standard output and files"

An off-tech argument: ask a local plumber if he'd would ever use
a tee piece instead of a pipe end piece.  I guess he would only
if he wouldn't have anything else at hand.
I never knew what 'tee' meant.  That makes sense now.
A word to the proposed patch: what should happen, if the user does
not give a file?
   A | B | tee -q
The patch just silently ignored that situation which feels wrong.

Therefore, adding a feature which does not really fit is wrong, and
contradicts the one-tool-for-one-purpose UNIX philosophy.
Agreed.
OTOH I understand that there's a little gap in the tool landscape.
Astonishingly, there doesn't seem to exist a trivial tool to redirect
from standard input (or any other input file descriptor) to a file.
I wrote such a little tool in the attached:

   $ src/sink --help
   Usage: src/sink [OPTION]... FILE
   Copy input stream to FILE.

   Mandatory arguments to long options are mandatory for short options too.

     -a, --append              append to the given FILE, do not overwrite
     -c, --create              ensure to create FILE, error if exists
     -i, --input-stream=FD     read from stream FD instead of standard input

   The default input stream number FD is 0, representing the standard input.

This allows not only to copy data from standard input, but from any
file descriptor open for reading.  It also allows control over
how the output file will be opened (e.g. with O_CREAT|E_EXCL).

The OPs case would look like:

   echo 'foo' | sudo sink /etc/foo
or
   echo 'foo' | sudo sink -a /etc/foo  # append.
or
   echo 'foo' | sudo sink -c /etc/foo  # ensure creation of the file.

I'm not sure if this will ever be considered for inclusion -
I just did it "for fun". ;-)
Tested-by: Alejandro Colomar <redacted>
Reviewed-by: Alejandro Colomar <redacted>

Much better than my patch.  :-)
Have a nice day,
Berny
Have a nice day!
Alex


--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On Sun, Jan 24, 2021 at 9:04 PM Bernhard Voelker
[off-list ref] wrote:
An off-tech argument: ask a local plumber if he'd would ever use
a tee piece instead of a pipe end piece.  I guess he would only
if he wouldn't have anything else at hand.
According to POSIX, tee writes to "zero or more files."[1] So the
"local plumber" analogy already doesn't hold, because a plumber would
never put in a tee and then immediately cap it off so that the flow
can only go to one place, but commands like `echo foo | tee | tee |
tee` are already explicitly allowed.
A word to the proposed patch: what should happen, if the user does
not give a file?
  A | B | tee -q
The patch just silently ignored that situation which feels wrong.
Personally, I like the idea of only having to type `echo foo | tee -q`
instead of `echo foo > /dev/null`, so I think the patch indeed does
the right thing in that case.

-Alex

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tee.html

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content

On 1/25/21 5:03 AM, Bernhard Voelker wrote:
OTOH I understand that there's a little gap in the tool landscape.
Astonishingly, there doesn't seem to exist a trivial tool to redirect
from standard input (or any other input file descriptor) to a file.
I wrote such a little tool in the attached:

   $ src/sink --help
   Usage: src/sink [OPTION]... FILE
   Copy input stream to FILE.

   Mandatory arguments to long options are mandatory for short options too.

     -a, --append              append to the given FILE, do not overwrite
     -c, --create              ensure to create FILE, error if exists
     -i, --input-stream=FD     read from stream FD instead of standard input

   The default input stream number FD is 0, representing the standard input.

This allows not only to copy data from standard input, but from any
file descriptor open for reading.  It also allows control over
how the output file will be opened (e.g. with O_CREAT|E_EXCL).

The OPs case would look like:

   echo 'foo' | sudo sink /etc/foo
or
   echo 'foo' | sudo sink -a /etc/foo  # append.
or
   echo 'foo' | sudo sink -c /etc/foo  # ensure creation of the file.

I'm not sure if this will ever be considered for inclusion -
I just did it "for fun". ;-)

Have a nice day,
Berny
By chance, I just found out that there is a tool very similar to 'sink' in moreutils [1].  It's called 'sponge'.

[1]: <https://joeyh.name/code/moreutils/>

So this feature already exists, and therefore I drop my patches.

Cheers,

Alex

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On Sun, Mar 14, 2021 at 3:44 AM Alejandro Colomar (man-pages)
[off-list ref] wrote:
On 1/25/21 5:03 AM, Bernhard Voelker wrote:
quoted
OTOH I understand that there's a little gap in the tool landscape.
Astonishingly, there doesn't seem to exist a trivial tool to redirect
from standard input (or any other input file descriptor) to a file.
I wrote such a little tool in the attached:

   $ src/sink --help
   Usage: src/sink [OPTION]... FILE
   Copy input stream to FILE.

   Mandatory arguments to long options are mandatory for short options too.

     -a, --append              append to the given FILE, do not overwrite
     -c, --create              ensure to create FILE, error if exists
     -i, --input-stream=FD     read from stream FD instead of standard input

   The default input stream number FD is 0, representing the standard input.

This allows not only to copy data from standard input, but from any
file descriptor open for reading.  It also allows control over
how the output file will be opened (e.g. with O_CREAT|E_EXCL).

The OPs case would look like:

   echo 'foo' | sudo sink /etc/foo
or
   echo 'foo' | sudo sink -a /etc/foo  # append.
or
   echo 'foo' | sudo sink -c /etc/foo  # ensure creation of the file.

I'm not sure if this will ever be considered for inclusion -
I just did it "for fun". ;-)

Have a nice day,
Berny
By chance, I just found out that there is a tool very similar to 'sink'
in moreutils [1].  It's called 'sponge'.

8 more quoted lines

Interesting, thanks for sharing. There's still no `sponge -q` option
though--it always writes either to a file or to standard output.

-Alex

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout

Message details and related content
On Mon, Mar 15, 2021 at 11:42 AM Alex Henrie [off-list ref] wrote:
On Sun, Mar 14, 2021 at 3:44 AM Alejandro Colomar (man-pages)
[off-list ref] wrote:
quoted
On 1/25/21 5:03 AM, Bernhard Voelker wrote:
quoted
OTOH I understand that there's a little gap in the tool landscape.
Astonishingly, there doesn't seem to exist a trivial tool to redirect
from standard input (or any other input file descriptor) to a file.
I wrote such a little tool in the attached:

   $ src/sink --help
   Usage: src/sink [OPTION]... FILE
   Copy input stream to FILE.

   Mandatory arguments to long options are mandatory for short options too.

     -a, --append              append to the given FILE, do not overwrite
     -c, --create              ensure to create FILE, error if exists
     -i, --input-stream=FD     read from stream FD instead of standard input

   The default input stream number FD is 0, representing the standard input.

This allows not only to copy data from standard input, but from any
file descriptor open for reading.  It also allows control over
how the output file will be opened (e.g. with O_CREAT|E_EXCL).

The OPs case would look like:

   echo 'foo' | sudo sink /etc/foo
or
   echo 'foo' | sudo sink -a /etc/foo  # append.
or
   echo 'foo' | sudo sink -c /etc/foo  # ensure creation of the file.

I'm not sure if this will ever be considered for inclusion -
I just did it "for fun". ;-)

Have a nice day,
Berny

16 more quoted lines

Actually, it looks like `pee` (also from moreutils) can be used for
throwing input into the void. So between `sponge` and `pee`, I think
all the use cases are covered!

-Alex
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help