tee: Add -q, --quiet option to not write to stdout
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): CAMMLpeRSh5HKi=sJV7y=pav26EzzP-yEe0+Dgp_=mtBUhtFvaQ@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
[CC += mtk, linux-api, freebsd, openbsd]
Quoted 14 lines · Alejandro Colomar (man-pages)
Hi Berny,
Quoted 11 lines · Bernhard Voelker
Quoted 2 lines · Alex Henrie
That said, I would love to see
tee -qadded 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
Quoted 39 lines
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 6 lines
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 4 lines
Have a nice day,
BernyKind regards,
Alex
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
PATCH v2 1/1 tee: Add -q, --quiet, --silent option to not write to stdout
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
---
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(-)
src/tee.c +14 -2
@@ -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 ) {
Signature · 1 line
2.30.0
Re: [PATCH v2] tee: Add -q, --quiet, --silent option to not write to stdout
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.
Quoted 83 lines · 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;Tools with a similar interface: grep
Signed-off-by Alejandro Colomar <[email protected]>---
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(-)src/tee.c +14
-2@@ -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 ) {
Signature · 4 lines
-- Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
PATCH 1/1 tee: Add -q, --quiet, --silent option to not write to stdout
In reply to Alejandro Colomar (man-pages)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(-)
src/tee.c +15 -3
@@ -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 ) {
Signature · 1 line
2.30.0
PATCH v3 1/1 tee: Add -q, --quiet, --silent option to not write to stdout
In reply to Alejandro Colomar (man-pages)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;
---
Resend as v3. I forgot to change the subject line. Everything else is the same as in <[email protected]>.
src/tee.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
src/tee.c +15 -3
@@ -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 ) {
Signature · 1 line
2.30.0
Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
Quoted 94 lines · 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/nullExample:
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 <[email protected]>---
Resend as v3. I forgot to change the subject line. Everything else is the same as in <[email protected]>.
src/tee.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)src/tee.c +15
-3@@ -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 ) {Signature · 6 lines
2.30.0 _______________________________________________ [email protected] mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[email protected]"
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
Quoted 15 lines · Teran McKinney
Quoted 14 lines · 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/nullExample:
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 <[email protected]>---
[...]
Quoted 13 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:
> fileTo overwrite.
Or
Quoted 9 lines
>> fileTo 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
Signature · 3 lines
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
In reply to Alejandro ColomarQuoted 9 lines · 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/nullExample:
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 81 lines
echo 'foo' | sudo tee
/etc/foo>/dev/null;Signed-off-by Alejandro Colomar <[email protected]>---
Resend as v3. I forgot to change the subject line. Everything else is the same as in <[email protected]>.
src/tee.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)src/tee.c +15
-3@@ -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 ) {Signature · 1 line
2.30.0
Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
Quoted 10 lines · Otto Moerbeek
Quoted 8 lines · 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/nullExample:
echo 'foo' | sudo tee -q
/etc/foo;
Quoted 8 lines
Quoted 1 line
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
In reply to Otto MoerbeekQuoted 3 lines · Otto Moerbeek
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
Quoted 10 lines · Alex Henrie
Quoted 3 lines · Otto Moerbeek
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]
Quoted 5 lines
-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
In reply to Alex HenrieQuoted 2 lines · Alex Henrie
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:
$ 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 inputThe 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
From 68473fb37ccfd65473ac186db4bd3bcc29560a40 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Mon, 25 Jan 2021 04:05:44 +0100
Subject: [PATCH] sink: add new program
* man/sink.x: Add file.
* src/sink.c: Likewise.
* AUTHORS (sink): Add entry.
* NEWS (New programs): Likewise.
* man/.gitignore (sink.1): Likewise.
* man/local.mk (man/sink.1): Likewise.
* po/POTFILES.in (src/sink.c): Likewise.
* src/.gitignore (sink): Likewise.
* README: Add the new tool to the list of programs.
* build-aux/gen-lists-of-programs.sh (normal_progs): Likewise.
* scripts/git-hooks/commit-msg (valid): Likewise.
* doc/coreutils.texi (sink invocation): Document the tool.
* tests/misc/sink.sh: Add a test.
* tests/local.mk (all_tests): Reference it.
* tests/misc/help-version.sh (sink_setup): Add test setup snippet.
--- AUTHORS | 1 + NEWS | 4 + README | 6 +- build-aux/gen-lists-of-programs.sh | 1 + doc/coreutils.texi | 87 +++++++++++- man/.gitignore | 1 + man/local.mk | 1 + man/sink.x | 6 + po/POTFILES.in | 1 + scripts/git-hooks/commit-msg | 2 +- src/.gitignore | 1 + src/sink.c | 205 +++++++++++++++++++++++++++++ tests/local.mk | 1 + tests/misc/help-version.sh | 1 + tests/misc/sink.sh | 146 ++++++++++++++++++++ 15 files changed, 456 insertions(+), 8 deletions(-) create mode 100644 man/sink.x create mode 100644 src/sink.c create mode 100755 tests/misc/sink.sh
AUTHORS +1 -0
@@ -79,6 +79,7 @@ sha384sum: Ulrich Drepper, Scott Miller, David Madore sha512sum: Ulrich Drepper, Scott Miller, David Madore shred: Colin Plumb shuf: Paul Eggert +sink: Bernhard Voelker sleep: Jim Meyering, Paul Eggert sort: Mike Haertel, Paul Eggert split: Torbjorn Granlund, Richard M. Stallman
NEWS +4 -0
@@ -2,6 +2,10 @@ GNU coreutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** New programs + + sink: copy data from an input stream to a file. + ** Bug fixes cp -a --attributes-only now never removes destination files,
README +3 -3
@@ -13,9 +13,9 @@ The programs that can be built with this package are: id install join kill link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm rmdir runcon seq sha1sum sha224sum sha256sum - sha384sum sha512sum shred shuf sleep sort split stat stdbuf stty sum sync - tac tail tee test timeout touch tr true truncate tsort tty uname unexpand - uniq unlink uptime users vdir wc who whoami yes + sha384sum sha512sum shred shuf sink sleep sort split stat stdbuf stty sum + sync tac tail tee test timeout touch tr true truncate tsort tty uname + unexpand uniq unlink uptime users vdir wc who whoami yes See the file NEWS for a list of major changes in the current release.
build-aux/gen-lists-of-programs.sh +1 -0
@@ -112,6 +112,7 @@ normal_progs=' sha512sum shred shuf + sink sleep sort split
doc/coreutils.texi +83 -4
116 lines not on this page · raw message
man/.gitignore +1 -0
@@ -74,6 +74,7 @@ sha384sum.1 sha512sum.1 shred.1 shuf.1 +sink.1 sleep.1 sort.1 split.1
man/local.mk +1 -0
@@ -141,6 +141,7 @@ man/sha384sum.1: src/sha384sum$(EXEEXT) man/sha512sum.1: src/sha512sum$(EXEEXT) man/shred.1: src/shred$(EXEEXT) man/shuf.1: src/shuf$(EXEEXT) +man/sink.1: src/sink$(EXEEXT) man/sleep.1: src/sleep$(EXEEXT) man/sort.1: src/sort$(EXEEXT) man/split.1: src/split$(EXEEXT)
man/sink.x new file +6 -0
@@ -0,0 +1,6 @@ +[NAME] +sink \- copy data from an input stream to a file +[DESCRIPTION] +.\" Add any additional description here +[SEE ALSO] +cat(1), tee(1)
po/POTFILES.in +1 -0
@@ -113,6 +113,7 @@ src/seq.c src/set-fields.c src/shred.c src/shuf.c +src/sink.c src/sleep.c src/sort.c src/split.c
scripts/git-hooks/commit-msg +1 -1
@@ -20,7 +20,7 @@ my @valid = qw( install join kill link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm rmdir runcon seq sha1sum sha224sum sha256sum - sha384sum sha512sum shred shuf sleep sort split stat stdbuf stty + sha384sum sha512sum shred shuf sink sleep sort split stat stdbuf stty sum sync tac tail tee test timeout touch tr true truncate tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
src/.gitignore +1 -0
@@ -86,6 +86,7 @@ sha384sum sha512sum shred shuf +sink sleep sort split
src/sink.c new file +205 -0
205 lines not on this page · raw message
tests/local.mk +1 -0
@@ -359,6 +359,7 @@ all_tests = \ tests/misc/shred-size.sh \ tests/misc/shuf.sh \ tests/misc/shuf-reservoir.sh \ + tests/misc/sink.sh \ tests/misc/sleep.sh \ tests/misc/sort.pl \ tests/misc/sort-benchmark-random.sh \
tests/misc/help-version.sh +1 -0
@@ -195,6 +195,7 @@ logname_setup () { args=--version; } nohup_setup () { args=--version; } printf_setup () { args=foo; } seq_setup () { args=10; } +sink_setup () { args=$tmp_out; } sleep_setup () { args=0; } stdbuf_setup () { args="-oL true"; } timeout_setup () { args=--version; }
tests/misc/sink.sh new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
2.30.0
Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
Quoted 22 lines · Bernhard Voelker
Quoted 2 lines · Alex Henrie
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.
Quoted 7 lines
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 9 lines
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.
Quoted 23 lines
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 inputThe 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:
Quoted 8 lines
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". ;-)
Much better than my patch. :-)
Quoted 4 lines
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
Hi Berny,
Quoted 39 lines · Alejandro Colomar (man-pages)
Quoted 22 lines · Bernhard Voelker
Quoted 2 lines · Alex Henrie
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.
Quoted 7 lines
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 6 lines
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.
Quoted 20 lines
Quoted 3 lines
Therefore, adding a feature which does not really fit is wrong, and contradicts the one-tool-for-one-purpose UNIX philosophy.
Agreed.
Quoted 14 lines
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
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 36 lines
Quoted 9 lines
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:
Quoted 8 lines
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 <[email protected]>Reviewed-by Alejandro Colomar <[email protected]>Much better than my patch. :-)
Quoted 4 lines
Have a nice day,
BernyHave a nice day!
AlexSignature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Signature · 4 lines
-- 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
In reply to Bernhard VoelkerQuoted 4 lines · Bernhard Voelker
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.
Quoted 4 lines
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
In reply to Bernhard VoelkerQuoted 29 lines · Bernhard Voelker
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 inputThe 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.
Quoted 6 lines
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
Signature · 3 lines
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
Quoted 41 lines · Alejandro Colomar (man-pages)
Quoted 29 lines · Bernhard Voelker
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 inputThe 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.Quoted 6 lines
I'm not sure if this will ever be considered for inclusion - I just did it "for fun". ;-)
Have a nice day,
BernyBy chance, I just found out that there is a tool very similar to 'sink' in moreutils [1]. It's called 'sponge'.
Quoted 7 lines
[1]: <https://joeyh.name/code/moreutils/>
So this feature already exists, and therefore I drop my patches.
Cheers,
Alex
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
Quoted 48 lines · Alex Henrie
Quoted 45 lines · Alejandro Colomar (man-pages)
Quoted 29 lines · Bernhard Voelker
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 inputThe 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.Quoted 6 lines
I'm not sure if this will ever be considered for inclusion - I just did it "for fun". ;-)
Have a nice day,
BernyBy 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.
Quoted 8 lines
Quoted 3 lines
Cheers,
Alex
Interesting, thanks for sharing. There's still no
sponge -qoption though--it always writes either to a file or to standard output.-Alex
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
Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
In reply to Alejandro ColomarAm 24.01.2021 um 13:18 schrieb Alejandro Colomar:
Quoted 11 lines
This is useful for using tee to just write to a file, at the end of a pipeline,
without having to redirect to/dev/nullExample:
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