The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: crossd@gmail.com (Dan Cross)
Subject: [TUHS] dmr note on BSD's sins
Date: Wed, 3 May 2017 08:54:19 -0400	[thread overview]
Message-ID: <CAEoi9W5hz74awSWhR5Mi3pgKKkFxo4OGOS8hGzbxSC6Sq2XMXg@mail.gmail.com> (raw)
In-Reply-To: <alpine.BSF.2.20.1705031055190.11767@aneurin.horsfall.org>

On Tue, May 2, 2017 at 8:59 PM, Dave Horsfall <dave at horsfall.org> wrote:

> On Tue, 2 May 2017, Doug McIlroy wrote:
> > With Steve's eloquent grump and cat -v on the table, I can't help
> > re-citing the peerless cardinal sin of
> >         less --help | wc
>
> Speaking of "cat", what really drives me nuts is "cat file | cmd"...
>
> What's wrong with "cmd < file" (or to really confuse newbies, "< file
> cmd")?


Ooo! Ooo! Ooo! I've actually got something for this....

First of all, there's nothing strictly speaking *wrong* with 'cmd < file'
and cat 'cat file | cmd' is definitely overused, often unintentionally and
out of ignorance.

However, 'cmd <file' requires 'file' as a literal string in the command;
`cat` can be useful when the file parameter may be optional. E.g., 'cat
"$@" | ...'. Now some folks will immediately respond by saying, "many
commands will read from stdin if a filename is not presented on the command
line, so why not, 'cmd "$@"'?" And that's certainly a valid question, to
which I would answer that the semantics of a command sometimes subtly
change when presented with one or more filenames as argument (e.g. 'grep'),
so using `cat` may suppress that behavior if desired. "But `grep` has the
`-h` option to tell it not to print the filename!" Yes, but `grep` is just
*one command* and not *all* of them do. The point being that 'cat' in a
pipeline has it's place, even if that place is rarely the place we see it.

Another, related use to cover up one of the more odious of recent design
decisions in Unix-like systems is to use `cat` at the *end* of the
pipeline. Some programs change behavior if they know that they are writing
into a tty; one can suppress that if one terminates the pipeline in `cat`.
This is surely a case of mis-using a feature to mask a bug, but it's often
useful regardless.

        - Dan C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170503/8eae661e/attachment.html>


  reply	other threads:[~2017-05-03 12:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03  0:52 Doug McIlroy
2017-05-03  0:59 ` Dave Horsfall
2017-05-03 12:54   ` Dan Cross [this message]
2017-05-03 13:09     ` Arthur Krewat
2017-05-03 13:46   ` Michael Kjörling
2017-05-03 14:57   ` Clem Cole
2017-05-03 15:34     ` arnold
2017-05-03 15:44       ` Clem Cole
  -- strict thread matches above, loose matches on Subject: below --
2017-05-03 13:41 Nemo
2017-05-03 22:18 ` Dave Horsfall
2017-05-04 14:59 ` Tim Bradshaw
2017-05-04 23:14   ` Larry McVoy
2017-05-05 14:01     ` Random832
2017-05-05 18:56       ` A. P. Garcia
2017-05-05 17:33     ` Tim Bradshaw
2017-05-01 17:25 ron minnich
2017-05-01 18:09 ` Toby Thain
2017-05-02 16:11   ` Steve Johnson
2017-05-02 16:39     ` Erik E. Fair
2017-05-02 16:43       ` ron minnich
2017-05-02 20:28     ` Diomidis Spinellis
     [not found]       ` <CAM4FNStH7KH6+ab0o_fYKfzutvPQ__0w0Zq5_6hk4AFP=+aSAw@mail.gmail.com>
2017-05-02 20:34         ` Daniel Camolês
2017-05-02 20:34       ` Steve Johnson
2017-05-02 21:22       ` Andy Kosela

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=CAEoi9W5hz74awSWhR5Mi3pgKKkFxo4OGOS8hGzbxSC6Sq2XMXg@mail.gmail.com \
    --to=crossd@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).