I'm writing a set of shell helper scripts - a kind of toolbox for simple data/text_files processing.

In it there will be some simple tools like, for example: dateToTimestamp or showParagraphHeads.

My question is:

Should I write them as stream-filters or parameter-only tools?

Let me explain it shortly. Some standard shell tools are obviously a stream-filters like awk, sed or lets say tr or sort, but others work only with parameters like date (this is setter/getter, but anyway).


So now, if I write a script that shows first line of every block of text (short line in awk/sed though) the answer is obvious because I need some multiline-stream/file to do that.


But if I write something that converts date from - say - YMDhms to timestamp then it can be done as a stream-filter but also as a parameter-only tool (similar to date) with usage like: dateToTimestamp DATE_IN_YMDhms

Now, both ways have their pros and cons. Sometimes it's easier to just use pipe and use my stream filter. Another time I have more complex data and need to use awk {system()} on some column then it's easier to use parameter-based tool.

I know this is a general question, but maybe you know some convention or guidelines that maybe exist somewhere in *nix world.


closed as primarily opinion-based by Michael Homer, Jeff Schaller, G-Man, cas, mdpc Feb 1 '18 at 23:13

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Bear in mind that programs like cat, awk, sed, grep, sort, wc, etc., will read from files whose names are given on the command line, and will read from standard input if no files are specified.  I believe that’s a good model, in general — but ultimately one should think about what makes the most sense for each command. – G-Man Feb 1 '18 at 2:49

Part of the Unix philosophy is to "write programs to handle text streams, because that is a universal interface.", or to use stream-filters.

That said, how do you want (or need) to use the tools?

Let the answer to that question answer your question on a tool-by-tool basis, since another part of the Unix philosophy is that a functionally simple program with a simple implementation is better than a program that behaves consistently with other programs.

So, to pull from your example, if a utility to convert date formats is really simple if it accepts parameters, then only accept parameters if that meets your needs.

Not the answer you're looking for? Browse other questions tagged or ask your own question.