ed (text editor)

From Wikipedia, the free encyclopedia
(Redirected from Ed (Unix))

Template:Short description

Page Module:Infobox/styles.css has no content.

ed
[[Programmer|Original authorTemplate:Pluralize from text]]Ken Thompson
[[Programmer|DeveloperTemplate:Pluralize from text]]AT&T Bell Laboratories
Initial release1973, 52–53 years ago
Template:Infobox software/simple
Written inC
EnginePage Template:Plainlist/styles.css has no content.Template:EditAtWikidata
Operating systemUnix, Unix-like, Plan 9
PlatformCross-platform
TypeText editor
LicensePlan 9: MIT License
WebsiteScript error: No such module "WikidataIB".
RepositoryPage Template:Plainlist/styles.css has no content.

Script error: No such module "Check for conflicting parameters".

Template:Tt (pronounced as distinct letters, /ˌˈd/)[1] is a line editor. It was one of the first features of the Unix operating system.[2] Although not commonly used today, it remains part of the POSIX and Open Group standards,[3] alongside the full-screen editor vi.

History

The ed text editor was one of the first three key elements of the Unix operating system—assembler, editor, and shell—developed by Ken Thompson in August 1969 on a PDP-7 at AT&T Bell Labs.[2] Many of its features came from the qed text editor developed at Thompson's alma mater University of California, Berkeley.[4] Thompson was very familiar with qed, and had reimplemented it on the CTSS and Multics systems. Thompson's versions of qed were notable as the first to implement regular expressions. Regular expressions are also implemented in ed, though their implementation is considerably less general than that in qed.

Dennis M. Ritchie produced what Doug McIlroy later described as the "definitive" ed,[5] and aspects of ed went on to influence ex, and later vi. The non-interactive Unix command grep was inspired by a common special use of qed and later ed, where the command g/re/p performs a global regular expression search and prints the lines containing matches. The Unix stream editor, sed, implemented many of the scripting features of qed that were not supported by ed on Unix.[6]

The ed commands are often imitated in other line-based editors. For example, CP/M's ED, EDLIN in early MS-DOS versions and 32-bit versions of Windows NT has a somewhat similar syntax, and text editors in many MUDs (LPMud and descendants, for example) use ed-like syntax. These editors, however, are typically more limited in function.

In current practice, ed is rarely used interactively, yet is sometimes used in shell scripts. For interactive use, ed was subsumed by the sam, vi and Emacs editors in the 1980s. ed can be found on virtually every version of Unix and Linux available, and as such is useful for people who have to work with multiple versions of Unix. On Unix-based operating systems, some utilities like SQL*Plus run ed as the editor if the EDITOR and VISUAL environment variables are not defined.[7] If something goes wrong, ed is sometimes the only editor available. This is often the only time when it is used interactively.

Features

The man page for GNU ed

Features of ed include:

The GNU version includes options intended to enhance feedback. Using ed -v -p: provides a simple prompt and enables more useful feedback messages.[8] The -p switch is defined in POSIX since XPG2 (1987).[3]

User experience

Known for its terseness, ed gives almost no feedback,[9] and has been called (by Peter H. Salus) "the most user-hostile editor ever created", even when compared to the contemporary (and notoriously complex) TECO.[2]Template:R/superscript For example, the message that ed produces in case of error and when it wants to confirm exit without saving, is merely "?". It does not report the current filename or line number, or even display the results of a change to the text, unless requested. Older versions (c. 1981) did not even ask for confirmation when a quit command was issued when there were unsaved changes.[9] This terseness was appropriate in early versions of Unix, when a console was a teletype[a], modems were slow, and memory was limited. As computer technology improved and these constraints loosened, editors with more feedback became the norm.

The glibc documentation notes an error code called ED with its description (errorstr) merely a single question mark, noting "the experienced user will know what is wrong."[10]

Example

Here is an example transcript of an ed session. For clarity, commands and text typed by the user are in normal color, and output from ed is gray color.

a
ed is the standard Unix text editor.
This is line number two.
.
2i
. ,l Template:Codett Template:Codett Template:Codett w text.txt Template:Codett Template:Codett ,l Template:Codett Template:Codett Template:Codett w text.txt Template:Codett q

The end result is a simple text file Page Template:Mono/styles.css has no content.text.txt containing the following text:

ed is the standard Unix text editor.
This is line number three.

Started with an empty file, the Page Template:Kbd/styles.css has no content.a command appends text (all ed commands are single letters). The command puts ed in insert mode, inserting the characters that follow and is terminated by a single dot on a line. The two lines that are entered before the dot end up in the file buffer. The Page Template:Kbd/styles.css has no content.2i command also goes into insert mode, and will insert the entered text (a single empty line in our case) before line two. All commands may be prefixed by a line number to operate on that line.

In the line Page Template:Kbd/styles.css has no content.,l, the lowercase L stands for the list command. The command is prefixed by a range, in this case Page Template:Kbd/styles.css has no content., which is a shortcut for Page Template:Kbd/styles.css has no content.1,$. A range is two line numbers separated by a comma (Page Template:Kbd/styles.css has no content.$ means the last line). In return, ed lists all lines, from first to last. These lines are ended with dollar signs, so that white space at the end of lines is clearly visible.

Once the empty line is inserted in line 2, the line which reads "This is line number two." is now actually the third line. This error is corrected with 3s/two/three/, a substitution command. The Page Template:Kbd/styles.css has no content.3 will apply it to the correct line; following the command is the text to be replaced, and then the replacement. Listing all lines with Page Template:Kbd/styles.css has no content.,l the line is shown now to be correct.

Page Template:Kbd/styles.css has no content.w text.txt writes the buffer to the file Page Template:Mono/styles.css has no content.text.txt making ed respond with Template:Codett, the number of characters written to the file. Page Template:Kbd/styles.css has no content.q will end an ed session.

See also

Notes

Page Template:Reflist/styles.css has no content.

  1. ^ ed is compatible with terminals like Teletype Model 33

References

Page Template:Reflist/styles.css has no content.

  1. ^ Page Module:Citation/CS1/styles.css has no content.Computerphile (2018-07-06), Where GREP Came From – Computerphile, archived from the original on 2021-12-11, retrieved 2020-10-21
  2. ^ a b c Page Module:Citation/CS1/styles.css has no content.Salus, Peter H. (2005). The Daemon, the Gnu and the Penguin. Groklaw. Archived from the original on 2010-05-05.
  3. ^ a b Template:Man
  4. ^ D. M. Ritchie and K. L. Thompson, "QED Text Editor", MM-70-1373-3 (June 1970), reprinted as "QED Text Editor Reference Manual", MHCC-004, Murray Hill Computing, Bell Laboratories (October 1972).
  5. ^ Page Module:Citation/CS1/styles.css has no content.McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.
  6. ^ Page Module:Citation/CS1/styles.css has no content."On the Early History and Impact of Unix". Archived from the original on 2017-09-07. Retrieved 2023-06-22. A while later a demand arose for another special-purpose program, gres, for substitution: g/re/s. Lee McMahon undertook to write it, and soon foresaw that there would be no end to the family: g/re/d, g/re/a, etc. As his concept developed it became sed…
  7. ^ Administering SQL*Plus Script error: No such module "webarchive".. Accessed 7/23/2016.
  8. ^ Template:Man
  9. ^ a b Page Module:Citation/CS1/styles.css has no content.Donald A. Norman (1981). "The truth about UNIX" (PDF). Datamation. Archived from the original (PDF) on 2014-04-16.
  10. ^ Page Module:Citation/CS1/styles.css has no content."The GNU C Library - Error Codes". www.gnu.org. Archived from the original on 2022-10-08. Retrieved 2022-10-08.

Page Module:Side box/styles.css has no content.Page Template:Sister project/styles.css has no content.

Lua error in package.lua at line 80: module 'Module:Navbox/configuration' not found. Template:Plan 9 commands Template:Ken Thompson navbox