coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not wri


From: Bernhard Voelker
Subject: Re: [PATCH v3 (resend)] tee: Add -q, --quiet, --silent option to not write to stdout
Date: Mon, 25 Jan 2021 05:03:48 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1

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.

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 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". ;-)

Have a nice day,
Berny

Attachment: 0001-sink-add-new-program.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]