[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: standard for stdin / args handling?
From: |
Pádraig Brady |
Subject: |
Re: standard for stdin / args handling? |
Date: |
Thu, 27 Dec 2012 02:14:43 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 |
On 12/26/2012 09:18 PM, Aaron Davies wrote:
afaict from my general *nx experience, the basic rule for text-handling utilities (filters, etc.) is as
follows: first, no argument(s) means stdin is used; second, argument(s) means stdin is ignored, unless
"-" is present as an argument, in which case stdin is used in the position in the sequence where
the first "-" occurs (later "-"s have no effect, presumably due to the way pipes behave);
finally, if no arguments and not receiving a pipe and in some sort of interactive context (stdin is a tty?),
stdin is accepted from the terminal (and handled line-by-line (rev(1)) or at end-of-file (tac(1)), as
appropriate).
That's the usual operation of a filter yes.
Though there are always exceptions like dd for example.
Note multiple '-' aren't usually ignored.
cat - - -
seq 10 | paste - - -
...
cat(1) is the canonical example.
my questions are: have i described the behavior correctly, and is there
anything (in any context--C, shell, etc.) to make creating new tools which
follow these rules easier?
I don't know of higher level abstractions for this behavior.
thanks,
Pádraig.