26 Welcome, New User! Unix utilities. As a result, some utilities take their options preceded by a dash, some don’t. Some read standard input, some don’t. Some write stan- dard output, some don’t. Some create files world writable, some don’t. Some report errors, some don’t. Some put a space between an option and a filename, some don’t. Unix was an experiment to build an operating system as clean and simple as possible. As an experiment, it worked, but as a production system the researchers at AT&T overshot their goal. In order to be usable by a wide number of people, an operating system must be rich. If the system does not provide that fundamental richness itself, users will graft functionality onto the underlying framework. The real problem of consistency and predict- ability, suggests Dave Mankins, may be that Unix provided programmers outside AT&T with no intellectual framework for making these additions. Date: Sat, 04 Mar 89 19:25:58 EST From: dm@think.com To: UNIX-HATERS Subject: Unix weenies at their own game Unix weenies like to boast about the conceptual simplicity of each command. What most people might think of as a subroutine, Unix weenies wrap up as a whole command, with its own argument syntax and options. This isn’t such a bad idea, since, in the absence of any other inter- preters, one can write pretty powerful programs by linking together these little subroutines. Too bad it never occurred to anyone to make these commands into real subroutines, so you could link them into your own program, instead of having to write your own regular expression parser (which is why ed, sed, grep, and the shells all have similar, but slightly different understandings of what a regular expression is).5 The highest achievement of the Unix-aesthetic is to have a command that does precisely one function, and does it well. Purists object that, after freshman programmers at Berkeley got through with it, the pro- gram “cat” which concatenates multiple files to its output6 now has 5Well, it did occur to someone, actually. Unfortunately, that someone worked on a version of Unix that became an evolutionary dead-end.
Consistently Inconsistent 27 OPTIONS. (“Cat came back from Berkeley waving flags,” in the words of Rob Pike, perhaps the ultimate Unix minimalist.) This philosophy, in the hands of amateurs, leads to inexplicably mind-numbing botches like the existence of two programs, “head” and “tail,” which print the first part or the last part of a file, depend- ing. Even though their operations are duals of one another, “head” and “tail” are different programs, written by different authors, and take different options! If only the laws of thermodynamics were operating here, then Unix would have the same lack of consistency and entropy as other systems that were accreted over time, and be no better or worse than them. However, archi- tectural flaws increase the chaos and surprise factor. In particular, pro- grams are not allowed to see the command line that invoked them, lest they spontaneously combust. The shell acts as an intermediary that sanitizes and synthesizes a command line for a program from the user’s typing. Unfortu- nately, the shell acts more like Inspector Clouseau than Florence Nightin- gale. We mentioned that the shell performs wildcard expansion, that is, it replaces the star (*) with a listing of all the files in a directory. This is flaw #1 the program should be calling a library to perform wildcard expansion. By convention, programs accept their options as their first argument, usu- ally preceded by a dash (–). This is flaw #2. Options (switches) and other arguments should be separate entities, as they are on VMS, DOS, Genera, and many other operationg systems. Finally, Unix filenames can contain most characters, including nonprinting ones. This is flaw #3. These archi- tectural choices interact badly. The shell lists files alphabetically when expanding “*”, and the dash (-) comes first in the lexicographic caste sys- tem. Therefore, filenames that begin with a dash (-) appear first when “*” is used. These filenames become options to the invoked program, yielding unpredictable, surprising, and dangerous behavior. Date: Wed, 10 Jan 90 10:40 CST From: kgg@lfcs.ed.ac.uk (Kees Goossens) Subject: Re: rm * Newsgroups: alt.folklore.computers 6Using “cat” to type files to your terminal is taking advantage of one of its side effects, not using the program for its “true purpose.”
Previous Page Next Page