From owner-freebsd-hackers@freebsd.org Sun Jan 24 17:52:02 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 60F3F4D4211 for ; Sun, 24 Jan 2021 17:52:02 +0000 (UTC) (envelope-from otto@drijf.net) Received: from clue.drijf.net (clue.drijf.net [94.142.244.34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DP0tn1190z3sCs; Sun, 24 Jan 2021 17:52:00 +0000 (UTC) (envelope-from otto@drijf.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=drijf.net; s=default; t=1611510710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6R9cxIIPJyVqbiYIwH3/tA/8c+6DhQciQFD9pBBqCaw=; b=dbWXWjPLe6u3ZvDorGvYtUhIlXOFmBV019x+6pShnH8uaVO1hK0XStDOnaXRQGDfMYb//m 7l4NV5JrDuD04Ih/HKSxhVZ+EAlMmse+MCtI+AQ2L6Kuq0tAuVB8GZfipy82zQzWPFJN5G h56U6zHDVb0LCPd4JbJn+wIQaKHo9y4= Received: from clue.drijf.net (clue.drijf.net [94.142.244.34]) by mx1.drijf.net (OpenSMTPD) with ESMTPSA id 30a2f150 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 24 Jan 2021 18:51:50 +0100 (CET) Date: Sun, 24 Jan 2021 18:51:48 +0100 From: Otto Moerbeek To: Alejandro Colomar Cc: Bernhard Voelker , Alex Henrie , Christian Groessler , =?iso-8859-1?Q?P=E1draig?= 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-Rspamd-Queue-Id: 4DP0tn1190z3sCs X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=fail (body hash did not verify) header.d=drijf.net header.s=default header.b=dbWXWjPL; dmarc=pass (policy=none) header.from=drijf.net; spf=pass (mx1.freebsd.org: domain of otto@drijf.net designates 94.142.244.34 as permitted sender) smtp.mailfrom=otto@drijf.net X-Spamd-Result: default: False [-0.90 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_DKIM_REJECT(0.00)[drijf.net:s=default]; R_SPF_ALLOW(-0.20)[+mx]; DKIM_TRACE(0.00)[drijf.net:-]; DMARC_POLICY_ALLOW(0.00)[drijf.net,none]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; RCVD_COUNT_ONE(0.00)[1]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RBL_DBL_DONT_QUERY_IPS(0.00)[94.142.244.34:from]; ASN(0.00)[asn:8283, ipnet:94.142.240.0/21, country:NL]; ONCE_RECEIVED(0.10)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(0.30)[0.304]; NEURAL_HAM_LONG(-1.00)[-1.000]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; SPAMHAUS_ZRD(0.00)[94.142.244.34:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWELVE(0.00)[18]; 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)[]; MAILMAN_DEST(0.00)[freebsd-hackers] X-Mailman-Approved-At: Mon, 25 Jan 2021 09:39:27 +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 17:52:02 -0000 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 > > 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 >