Hints For Writing Unix Tools

Marius Eriksen has a useful post for those not afraid to leave the comfort of the GUI for the command line. It’s long been noted that the ability of Unix to compose tools into pipelines is extraordinarily powerful and makes building one-off custom commands almost trivially easy.

This composability is a feature of virtually all Unix command line tools but sometimes a specific workflow or domain requires a new tool that can’t be built up from existing ones. Eriksen’s post, Hints For Writing Unix Tools, offers some pointers for building such a tool. The main principle is too make sure the new tool composes well.

First and foremost that means reading from STDIN and writing to STDOUT. That’s the key to making it possible to use the tool in a pipeline. Two other, almost as important, principles are to avoid interactive input and to write error messages and other diagnostic output to STDERR.

There’s more, of course, so be sure to take a look at Eriksen’s post to get the whole story. I know that it’s a popular opinion among some younger developers that the command line is dinosaur land but I think there’s a good case to be made that if you can’t build command line pipelines, you’re working too hard. Once you accept that, it’s pretty clear that knowing how to build your own pipeline applications is a useful thing to know.

This entry was posted in Programming and tagged , . Bookmark the permalink.