is the truly Unix-minimalist way of plain-text editing. It dates from
the days of teletypes. It has a simple, austere CLI, and there is
no screen display. In the following listing, computer output is
sample.txt: No such file or directory
# This is a comment line, not a command.
# The message above warns that the sample.txt file is newly created.
the quick brown fox
jumped over the lazy dog
# That was an append command, which added text to the file.
# The dot on a line by itself terminated the append.
# On line 1, replace the first substring matching an f followed by a
# lowercase alphabetic followed by x with ‘dragon’. The
# substitute command accepts basic regular expressions.
the quick brown dragon
jumped over the lazy dog
# Print all lines from 1 to the last.
# That wrote the file to disk. The ‘q’ command ends the
# editing session.
Unbelievable as it may seem to a modern reader, most of Unix's
original code was written with this editor. The reader with DOS
experience may recognize here the original on which
EDLIN was (crudely) modeled.
If one defines the job of an editor simply as enabling the user
to create and modify plain text files,
is entirely sufficient for the job. Importantly to the Unix view of
design correctness, it does nothing else. Many old-school Unix
programmers half-seriously maintain that all editors with more
features than ed has are simply bloated — and a few still who
seriously believe this.
Appropriately, ed was Ken Thompson's
deliberate simplification of the earlier
— which was very similar (and the first editor to use regular
expressions in the characteristic Unix way) but had multiple-buffer
capability that Ken deliberately discarded. He judged it not worth
the additional complexity.
A notable characteristic of ed(1) and all its descendants is the
object-operation format of its commands (the session example shows an
explicit range on the ‘p’ command). There is a relatively
powerful syntax for specifying line ranges, either numerically, or by
regular-expression pattern match, or by special shorthands for the
current and last line. Most editor operations can be applied to any
range. This is a good example of orthogonality.
is primarily used as a program-driven editing tool in scripts —
a role to which editors with more elaborate modes of interactivity are
unsuited. There is a close variant called
which adds a few useful interactivity features such as command
prompts; it is occasionally useful in rare cases when editing must be
done over a slow serial line, or in certain unusual crash-recovery
situations where the library support needed to run other editors is
not accessible. For these reasons, every Unix includes an
ed implementation and most include
ex as well.
stream editor mentioned in Chapter9 is also closely related to ed; many
of the basic commands are the same, though designed to be invoked
through command-line switches rather than from standard input.
Almost all Unix programmers have strayed from the path of
austerity and minimalist virtue enough to normally use editors that at
least present a roguelike, screen-oriented interface. However, the
fact that the religion of ed
persists says a great deal that is worth
noting about the Unix mindset.