From: Teran McKinney <sega01@go-beyond.org>
To: Alejandro Colomar <alx.manpages@gmail.com>
Cc: Bernhard Voelker <mail@bernhard-voelker.de>,
Alex Henrie <alexhenrie24@gmail.com>,
Christian Groessler <chris@groessler.org>,
P??draig Brady <P@draigbrady.com>, Coreutils <coreutils@gnu.org>,
William Ahern <william@25thandclement.com>,
Erik Auerswald <auerswal@unix-ag.uni-kl.de>,
Eric Pruitt <eric.pruitt@gmail.com>,
Jeffrey Walton <noloader@gmail.com>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Fabrice BAUZAC <noon@mykolab.com>,
tech@openbsd.org, freebsd-hackers@freebsd.org,
linux-api@vger.kernel.org, juli@clockworksquid.com, ed@nuxi.nl,
oshogbo@freebsd.org
Subject: Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
Date: Sun, 24 Jan 2021 16:11:34 +0000 [thread overview]
Message-ID: <YA2cNr/BQw1fAhwn@daemon> (raw)
In-Reply-To: <20210124121845.38293-1-alx.manpages@gmail.com>
On 2021-01-24 13-18-46 , 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)
>
> echo 'foo' | sudo tee /etc/foo >/dev/null;
>
> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
> ---
>
> Resend as v3. I forgot to change the subject line.
> Everything else is the same as in
> <20210123145356.53962-1-alx.manpages@gmail.com>.
>
> 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
>
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
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
next prev parent reply other threads:[~2021-01-24 16:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210121131735.317701-1-alx.manpages@gmail.com>
[not found] ` <8aa1d0b4-d2ec-7d18-120b-cae59708767c@draigBrady.com>
[not found] ` <424b9fb9-c740-1a2f-bd79-0b4035104698@gmail.com>
[not found] ` <e1a3b389-b808-92db-258d-85b60748b4dc@bernhard-voelker.de>
[not found] ` <06fb3df3-a956-3ec1-eadb-82fd89ec62d5@gmail.com>
[not found] ` <af2fb24a-a03a-35ef-c86e-545844b61a8d@groessler.org>
[not found] ` <CAMMLpeRSh5HKi=sJV7y=pav26EzzP-yEe0+Dgp_=mtBUhtFvaQ@mail.gmail.com>
[not found] ` <3bb6a134-c477-116c-182d-d6e24dc342e0@bernhard-voelker.de>
[not found] ` <f78ec1a9-f07f-de20-26cc-4be254e3e921@gmail.com>
2021-01-21 22:49 ` [PATCH] tee: Add -q, --quiet option to not write to stdout Alejandro Colomar (man-pages)
2021-01-21 23:12 ` [PATCH v2] tee: Add -q, --quiet, --silent " Alejandro Colomar
2021-01-22 18:25 ` Alejandro Colomar (man-pages)
2021-01-23 14:53 ` [PATCH] " Alejandro Colomar
2021-01-24 12:18 ` [PATCH v3 (resend)] " Alejandro Colomar
2021-01-24 16:11 ` Teran McKinney [this message]
2021-01-24 16:22 ` Alejandro Colomar (man-pages)
2021-01-24 17:51 ` Otto Moerbeek
2021-01-24 17:58 ` Theo de Raadt
2021-01-24 20:01 ` Alex Henrie
2021-01-24 20:22 ` Otto Moerbeek
2021-01-25 4:03 ` Bernhard Voelker
2021-01-25 11:33 ` Alejandro Colomar (man-pages)
2021-01-26 9:08 ` Alejandro Colomar (man-pages)
2021-01-27 1:40 ` Alex Henrie
2021-03-14 9:44 ` Alejandro Colomar (man-pages)
2021-03-15 17:42 ` Alex Henrie
2021-03-15 20:20 ` Alex Henrie
2021-01-25 16:06 ` Philipp-Joachim Ost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YA2cNr/BQw1fAhwn@daemon \
--to=sega01@go-beyond.org \
--cc=P@draigbrady.com \
--cc=alexhenrie24@gmail.com \
--cc=alx.manpages@gmail.com \
--cc=auerswal@unix-ag.uni-kl.de \
--cc=chris@groessler.org \
--cc=coreutils@gnu.org \
--cc=ed@nuxi.nl \
--cc=eric.pruitt@gmail.com \
--cc=freebsd-hackers@freebsd.org \
--cc=juli@clockworksquid.com \
--cc=linux-api@vger.kernel.org \
--cc=mail@bernhard-voelker.de \
--cc=mtk.manpages@gmail.com \
--cc=noloader@gmail.com \
--cc=noon@mykolab.com \
--cc=oshogbo@freebsd.org \
--cc=tech@openbsd.org \
--cc=william@25thandclement.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.