From owner-freebsd-hackers@freebsd.org Sun Jan 24 16:12:38 2021 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 632684D1435 for ; Sun, 24 Jan 2021 16:12:38 +0000 (UTC) (envelope-from sega01@go-beyond.org) Received: from haggis.mythic-beasts.com (haggis.mythic-beasts.com [IPv6:2a00:1098:0:86:1000:0:2:1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DNyh52TXBz3l5Z; Sun, 24 Jan 2021 16:12:36 +0000 (UTC) (envelope-from sega01@go-beyond.org) Received: from [174.126.29.109] (port=59666 helo=localhost) by haggis.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1l3hza-0007wT-1G; Sun, 24 Jan 2021 16:11:59 +0000 Date: Sun, 24 Jan 2021 16:11:34 +0000 From: Teran McKinney To: Alejandro Colomar Cc: Bernhard Voelker , Alex Henrie , Christian Groessler , P??draig Brady , Coreutils , William Ahern , Erik Auerswald , Eric Pruitt , Jeffrey Walton , Michael Kerrisk , Fabrice BAUZAC , 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 Message-ID: References: <1f8ce444-35e2-56a7-dbd1-34e885372b11@gmail.com> <20210124121845.38293-1-alx.manpages@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210124121845.38293-1-alx.manpages@gmail.com> X-BlackCat-Spam-Score: 4 X-Spam-Status: No, score=0.4 X-Rspamd-Queue-Id: 4DNyh52TXBz3l5Z X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of sega01@go-beyond.org designates 2a00:1098:0:86:1000:0:2:1 as permitted sender) smtp.mailfrom=sega01@go-beyond.org X-Spamd-Result: default: False [-1.50 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; MAILMAN_DEST(0.00)[freebsd-hackers]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1098::86:1000:0:2:1]; RCVD_IN_DNSWL_MED(-0.20)[2a00:1098:0:86:1000:0:2:1:from]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RBL_DBL_DONT_QUERY_IPS(0.00)[2a00:1098:0:86:1000:0:2:1:from]; ASN(0.00)[asn:44684, ipnet:2a00:1098::/32, country:GB]; R_DKIM_NA(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[go-beyond.org]; SPAMHAUS_ZRD(0.00)[2a00:1098:0:86:1000:0:2:1:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWELVE(0.00)[18]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[bernhard-voelker.de,gmail.com,groessler.org,draigbrady.com,gnu.org,25thandclement.com,unix-ag.uni-kl.de,mykolab.com,openbsd.org,freebsd.org,vger.kernel.org,clockworksquid.com,nuxi.nl]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[]; RCVD_COUNT_TWO(0.00)[2] X-Mailman-Approved-At: Mon, 25 Jan 2021 06:20:00 +0000 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Technical discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2021 16:12:40 -0000 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 > --- > > 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