Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

ed (software)

From Wikipedia, the free encyclopedia
(Redirected fromEd (text editor))
Line-oriented text editor for Unix
ed
Theed text editor
Original author(s)Ken Thompson
Developer(s)AT&T Bell Laboratories
Initial release1973, 51–52 years ago
Written inC
Operating systemUnix,Unix-like,Plan 9
PlatformCross-platform
TypeText editor
LicensePlan 9:MIT License

ed (pronounced as distinct letters,/ˌˈd/)[1] is aline editor forUnix andUnix-like operating systems. It was one of the first parts of the Unix operating system that was developed, in August 1969.[2] It remains part of thePOSIX andOpen Group standards for Unix-based operating systems,[3] alongside the more sophisticated full-screen editorvi.

History and influence

[edit]

The ed text editor was one of the first three key elements of the Unix operating system—assembler,editor, andshell—developed byKen Thompson in August 1969 on aPDP-7 atAT&T Bell Labs.[2] Many features of ed came from theqed text editor developed at Thompson'salma materUniversity of California, Berkeley.[4] Thompson was very familiar with qed, and had reimplemented it on theCTSS andMultics systems. Thompson's versions of qed were notable as the first to implementregular expressions. Regular expressions are also implemented in ed, though their implementation is considerably less general than that in qed.

Dennis M. Ritchie produced whatDoug McIlroy later described as the "definitive" ed,[5] and aspects of ed went on to influenceex, which in turn spawnedvi. The non-interactive Unix commandgrep was inspired by a common special use of qed and later ed, where the commandg/re/p performs aglobalregularexpression search andprints the lines containing matches. The Unix stream editor,sed implemented many of the scripting features ofqed that were not supported by ed on Unix.[6][failed verification][7]

Features

[edit]

Features of ed include:

Known for its terseness, ed, compatible withteletype terminals likeTeletype Model 33, gives almost no visual feedback,[8] and has been called (byPeter H. Salus) "the most user-hostile editor ever created", even when compared to the contemporary (and notoriously complex)TECO.[2] For example, the message that ed will produce in case of error,and when it wants to make sure the user wishes to quit without saving, is "?". 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 without the user saving changes.[8] This terseness was appropriate in the early versions of Unix, when consoles wereteletypes,modems were slow, andmemory was precious. As computer technology improved and these constraints were loosened, editors with more visual feedback became the norm.

Theman page for ed

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

The version of ed provided byGNU has a few switches to enhance the feedback. Usinged -v -p: provides a simple prompt and enables more useful feedback messages.[10] The-p switch is defined in POSIX sinceXPG2 (1987).[3]

The ed commands are often imitated in other line-based editors. For example,EDLIN in earlyMS-DOS versions and32-bit versions ofWindows NT has a somewhat similar syntax, and text editors in manyMUDs (LPMud and descendants, for example) use ed-like syntax. These editors, however, are typically more limited in function.

Example

[edit]

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

aed is the standard Unix text editor.This is line number two..2i
.,led is the standard Unix text editor.$$This is line number two.$w text.txt633s/two/three/,led is the standard Unix text editor.$$This is line number three.$w text.txt65q

The end result is a simple text filetext.txt containing the following text:

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

Started with an empty file, thea command appends text (all ed commands are single letters). The command puts ed ininsert 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. The2i 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,l, the lowercase L stands for the list command. The command is prefixed by a range, in this case, which is a shortcut for1,$. A range is two line numbers separated by a comma ($ 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 with3s/two/three/, a substitution command. The3 will apply it to the correct line; following the command is the text to be replaced, and then the replacement. Listing all lines with,l the line is shown now to be correct.

w text.txt writes the buffer to the filetext.txt making ed respond with65, the number of characters written to the file.q will end an ed session.

Cultural references

[edit]

TheGNU Project has numerous jokes around ed hosted on its website. In addition, theglibc documentation notes anerror code calledED with its description (errorstr) merely a single question mark, noting "the experienced user will know what is wrong."[11]

See also

[edit]

References

[edit]
  1. ^Computerphile (2018-07-06),Where GREP Came From – Computerphile,archived from the original on 2021-12-11, retrieved2020-10-21
  2. ^abcSalus, Peter H. (2005).The Daemon, the Gnu and the Penguin.Groklaw. Archived fromthe original on 2010-05-05.
  3. ^abed – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Group
  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. ^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. ^Raymond, Eric (2003)."The Art of Unix Programming"(PDF).Archived(PDF) from the original on June 15, 2023. RetrievedJune 14, 2023.
  7. ^"On the Early History and Impact of Unix".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…
  8. ^abDonald A. Norman (1981)."The truth about UNIX"(PDF).Datamation. Archived fromthe original(PDF) on 2014-04-16.
  9. ^Administering SQL*Plus. Accessed 7/23/2016.
  10. ^ed(1) – Linux General CommandsManual
  11. ^"The GNU C Library - Error Codes".www.gnu.org.

External links

[edit]
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Processes
User environment
Text processing
Shell builtins
Networking
Searching
Software development
Miscellaneous
Operating systems
Programming languages
Software
Associated institutions
Other
Retrieved from "https://en.wikipedia.org/w/index.php?title=Ed_(software)&oldid=1272174909"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp