From owner-freebsd-hackers@freebsd.org Mon Jan 25 11:33: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 BFABA4DE38E for ; Mon, 25 Jan 2021 11:33:38 +0000 (UTC) (envelope-from alx.manpages@gmail.com) Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DPSRk4Nnhz3pW4; Mon, 25 Jan 2021 11:33:38 +0000 (UTC) (envelope-from alx.manpages@gmail.com) Received: by mail-wr1-x432.google.com with SMTP id g10so12005506wrx.1; Mon, 25 Jan 2021 03:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UndO6GMVVZmcMmeat9dl3kmBPjIg2CugQuFU3Qe+syA=; b=BWY1cdaIaXtNsoBI1CL94KUSaVZc4YPaLvwxnaI5Ua5JhJbzrpRNdhCerYVtrU/vqv naqE+1sI0m3ANvWz3eikFQG3a6drkyzg9oRE0aC0hSR88Y8nbIpRuRNozVSXwPhWM7Jr xCnkxyoXIIhvyCYVX0SEHW5+c4Faq76r0QXtfVPSChhuQ9SOmhQfDSEX8CLwmyc8AcRK U6q7izAK66I/7zFCIG6aoyTjyn7N2sT5CCl2bm2QSSVyITAGO4v+D5i9iMCDiq4dbEO8 rqjA6OXfDhxeEU3KVflD77eud8imVjklpG496tjbKafd/y7/3cauqM8wggxiYx9jxF6b 6e5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UndO6GMVVZmcMmeat9dl3kmBPjIg2CugQuFU3Qe+syA=; b=tQrd2F/sWxR2fCAvtIvTfYjApL0hO9S3VbderAOs8ZNe0Z6W420pcxrcJ99pWJuHeX 1UnBtdDx84Y4mX8sGtQOxPGbnafjbrSS4iPueFAoqI1gQGCMLFyeewsPOONtM+Q4iXeY f7bsdKTd99qvcFvO/MsJinXbcGuCX3CyVBfGBO6xjf1l/xH7wLN8S05qHowUArPfmkl/ /Rsx5aTndI6Rn9BtQlKn6S2JxLWUTf6S/xTvuOQCW5iIsu6lp/G/bXQUMRJMU8NESYyh mzGgIdLbrH00lW9dghUUiyiHcuE1hpnTWIQmYgr82U84aLVQXJFeucJcETdHtiHqV0zE bkWg== X-Gm-Message-State: AOAM532nvGN9FrOnaZbkMgy/8nEGx5o3fFCmC3sYvFsm1IaudBedtKb3 vANSLBatqvxfE9xE2zaS1Os= X-Google-Smtp-Source: ABdhPJxQajBxHs+X8bVvEq65CY8ZT27zqXuQFKWROK50rmJw6Ks4jGRr/doMBaLndHNsyL+8QrsRNQ== X-Received: by 2002:adf:e348:: with SMTP id n8mr468706wrj.148.1611574416444; Mon, 25 Jan 2021 03:33:36 -0800 (PST) Received: from [10.8.0.134] ([195.53.121.100]) by smtp.gmail.com with ESMTPSA id n6sm20254332wmi.23.2021.01.25.03.33.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jan 2021 03:33:35 -0800 (PST) Subject: Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout To: Bernhard Voelker , Alex Henrie , Otto Moerbeek , Coreutils Cc: Fabrice BAUZAC , juli@clockworksquid.com, Jeffrey Walton , freebsd-hackers@freebsd.org, William Ahern , Roman Czyborra , oshogbo@freebsd.org, tech@openbsd.org, Christian Groessler , linux-api@vger.kernel.org, Michael Kerrisk , ed@nuxi.nl, Eric Pruitt References: <1f8ce444-35e2-56a7-dbd1-34e885372b11@gmail.com> <20210124121845.38293-1-alx.manpages@gmail.com> From: "Alejandro Colomar (man-pages)" Message-ID: Date: Mon, 25 Jan 2021 12:33:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4DPSRk4Nnhz3pW4 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; TAGGED_RCPT(0.00)[]; REPLY(-4.00)[]; TAGGED_FROM(0.00)[] X-Mailman-Approved-At: Mon, 25 Jan 2021 19:42:25 +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: Mon, 25 Jan 2021 11:33:38 -0000 On 1/25/21 5:03 AM, Bernhard Voelker wrote: > 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. 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 Reviewed-by: Alejandro Colomar 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/