logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ed.1p (48277B)


  1. '\" et
  2. .TH ED "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. ed
  12. \(em edit text
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. ed \fB[\fR-p \fIstring\fB] [\fR-s\fB] [\fIfile\fB]\fR
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR ed
  21. utility is a line-oriented text editor that uses two modes:
  22. .IR "command mode"
  23. and
  24. .IR "input mode" .
  25. In command mode the input characters shall be interpreted as commands,
  26. and in input mode they shall be interpreted as text. See the EXTENDED
  27. DESCRIPTION section.
  28. .P
  29. If an operand is
  30. .BR '\-' ,
  31. the results are unspecified.
  32. .SH OPTIONS
  33. The
  34. .IR ed
  35. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  36. .IR "Section 12.2" ", " "Utility Syntax Guidelines",
  37. except for the unspecified usage of
  38. .BR '\-' .
  39. .P
  40. The following options shall be supported:
  41. .IP "\fB\-p\ \fIstring\fR" 10
  42. Use
  43. .IR string
  44. as the prompt string when in command mode. By default, there shall be
  45. no prompt string.
  46. .IP "\fB\-s\fP" 10
  47. Suppress the writing of byte counts by
  48. .BR e ,
  49. .BR E ,
  50. .BR r ,
  51. and
  52. .BR w
  53. commands and of the
  54. .BR '!'
  55. prompt after a !\fIcommand\fR.
  56. .SH OPERANDS
  57. The following operand shall be supported:
  58. .IP "\fIfile\fR" 10
  59. If the
  60. .IR file
  61. argument is given,
  62. .IR ed
  63. shall simulate an
  64. .BR e
  65. command on the file named by the pathname,
  66. .IR file ,
  67. before accepting commands from the standard input.
  68. .SH STDIN
  69. The standard input shall be a text file consisting of commands, as
  70. described in the EXTENDED DESCRIPTION section.
  71. .SH "INPUT FILES"
  72. The input files shall be text files.
  73. .SH "ENVIRONMENT VARIABLES"
  74. The following environment variables shall affect the execution of
  75. .IR ed :
  76. .IP "\fIHOME\fP" 10
  77. Determine the pathname of the user's home directory.
  78. .IP "\fILANG\fP" 10
  79. Provide a default value for the internationalization variables that are
  80. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  81. .IR "Section 8.2" ", " "Internationalization Variables"
  82. for the precedence of internationalization variables used to determine
  83. the values of locale categories.)
  84. .IP "\fILC_ALL\fP" 10
  85. If set to a non-empty string value, override the values of all the
  86. other internationalization variables.
  87. .IP "\fILC_COLLATE\fP" 10
  88. .br
  89. Determine the locale for the behavior of ranges, equivalence classes,
  90. and multi-character collating elements within regular expressions.
  91. .IP "\fILC_CTYPE\fP" 10
  92. Determine the locale for the interpretation of sequences of bytes of
  93. text data as characters (for example, single-byte as opposed to
  94. multi-byte characters in arguments and input files) and the behavior of
  95. character classes within regular expressions.
  96. .IP "\fILC_MESSAGES\fP" 10
  97. .br
  98. Determine the locale that should be used to affect the format and
  99. contents of diagnostic messages written to standard error and
  100. informative messages written to standard output.
  101. .IP "\fINLSPATH\fP" 10
  102. Determine the location of message catalogs for the processing of
  103. .IR LC_MESSAGES .
  104. .SH "ASYNCHRONOUS EVENTS"
  105. The
  106. .IR ed
  107. utility shall take the standard action for all signals (see the
  108. ASYNCHRONOUS EVENTS section in
  109. .IR "Section 1.4" ", " "Utility Description Defaults")
  110. with the following exceptions:
  111. .IP SIGINT 10
  112. The
  113. .IR ed
  114. utility shall interrupt its current activity, write the string
  115. .BR \(dq?\en\(dq
  116. to standard output, and return to command mode (see the EXTENDED
  117. DESCRIPTION section).
  118. .IP SIGHUP 10
  119. If the buffer is not empty and has changed since the last write, the
  120. .IR ed
  121. utility shall attempt to write a copy of the buffer in a file. First,
  122. the file named
  123. .BR ed.hup
  124. in the current directory shall be used; if that fails, the file named
  125. .BR ed.hup
  126. in the directory named by the
  127. .IR HOME
  128. environment variable shall be used. In any case, the
  129. .IR ed
  130. utility shall exit without writing the file to the currently
  131. remembered pathname and without returning to command mode.
  132. .IP SIGQUIT 10
  133. The
  134. .IR ed
  135. utility shall ignore this event.
  136. .SH STDOUT
  137. Various editing commands and the prompting feature (see
  138. .BR \-p )
  139. write to standard output, as described in the EXTENDED DESCRIPTION
  140. section.
  141. .SH STDERR
  142. The standard error shall be used only for diagnostic messages.
  143. .SH "OUTPUT FILES"
  144. The output files shall be text files whose formats are dependent on the
  145. editing commands given.
  146. .SH "EXTENDED DESCRIPTION"
  147. The
  148. .IR ed
  149. utility shall operate on a copy of the file it is editing; changes made
  150. to the copy shall have no effect on the file until a
  151. .BR w
  152. (write) command is given. The copy of the text is called the
  153. .IR buffer .
  154. .P
  155. Commands to
  156. .IR ed
  157. have a simple and regular structure: zero, one, or two
  158. .IR addresses
  159. followed by a single-character
  160. .IR command ,
  161. possibly followed by parameters to that command. These addresses
  162. specify one or more lines in the buffer. Every command that requires
  163. addresses has default addresses, so that the addresses very often can
  164. be omitted. If the
  165. .BR \-p
  166. option is specified, the prompt string shall be written to standard
  167. output before each command is read.
  168. .P
  169. In general, only one command can appear on a line. Certain commands
  170. allow text to be input. This text is placed in the appropriate place in
  171. the buffer. While
  172. .IR ed
  173. is accepting text, it is said to be in \fIinput mode\fR. In this mode,
  174. no commands shall be recognized; all input is merely collected. Input
  175. mode is terminated by entering a line consisting of two characters: a
  176. <period>
  177. (\c
  178. .BR '.' )
  179. followed by a
  180. <newline>.
  181. This line is not considered part of the input text.
  182. .SS "Regular Expressions in ed"
  183. .P
  184. The
  185. .IR ed
  186. utility shall support basic regular expressions, as described in the Base Definitions volume of POSIX.1\(hy2017,
  187. .IR "Section 9.3" ", " "Basic Regular Expressions".
  188. Since regular expressions in
  189. .IR ed
  190. are always matched against single lines (excluding the terminating
  191. <newline>
  192. characters), never against any larger section of text, there is no way
  193. for a regular expression to match a
  194. <newline>.
  195. .P
  196. A null RE shall be equivalent to the last RE encountered.
  197. .P
  198. Regular expressions are used in addresses to specify lines, and in some
  199. commands (for example, the
  200. .BR s
  201. substitute command) to specify portions of a line to be substituted.
  202. .SS "Addresses in ed"
  203. .P
  204. Addressing in
  205. .IR ed
  206. relates to the current line. Generally, the current line is the last
  207. line affected by a command. The current line number is the address of
  208. the current line. If the edit buffer is not empty, the initial value
  209. for the current line shall be the last line in the edit buffer;
  210. otherwise, zero.
  211. .P
  212. Addresses shall be constructed as follows:
  213. .IP " 1." 4
  214. The
  215. <period>
  216. character (\c
  217. .BR '.' )
  218. shall address the current line.
  219. .IP " 2." 4
  220. The
  221. <dollar-sign>
  222. character (\c
  223. .BR '$' )
  224. shall address the last line of the edit buffer.
  225. .IP " 3." 4
  226. The positive decimal number
  227. .IR n
  228. shall address the
  229. .IR n th
  230. line of the edit buffer.
  231. .IP " 4." 4
  232. The
  233. <apostrophe>-x
  234. character pair (\c
  235. .BR \(dq\(aqx\(dq )
  236. shall address the line marked with the mark name character
  237. .IR x ,
  238. which shall be a lowercase letter from the portable character set. It
  239. shall be an error if the character has not been set to mark a line or
  240. if the line that was marked is not currently present in the edit
  241. buffer.
  242. .IP " 5." 4
  243. A BRE enclosed by
  244. <slash>
  245. characters (\c
  246. .BR '/' )
  247. shall address the first line found by searching forwards from the line
  248. following the current line toward the end of the edit buffer and
  249. stopping at the first line for which the line excluding the
  250. terminating
  251. <newline>
  252. matches the BRE. The BRE consisting of a null BRE delimited by a pair of
  253. <slash>
  254. characters shall address the next line for which the line excluding
  255. the terminating
  256. <newline>
  257. matches the last BRE encountered. In addition, the second
  258. <slash>
  259. can be omitted at the end of a command line. Within the BRE, a
  260. <backslash>-\c
  261. <slash>
  262. pair (\c
  263. .BR \(dq\e/\(dq )
  264. shall represent a literal
  265. <slash>
  266. instead of the BRE delimiter. If necessary, the search shall wrap around
  267. to the beginning of the buffer and continue up to and including the
  268. current line, so that the entire buffer is searched.
  269. .IP " 6." 4
  270. A BRE enclosed by
  271. <question-mark>
  272. characters (\c
  273. .BR '?' )
  274. shall address the first line found by searching backwards from the line
  275. preceding the current line toward the beginning of the edit buffer and
  276. stopping at the first line for which the line excluding the terminating
  277. <newline>
  278. matches the BRE. The BRE consisting of a null BRE delimited by a pair
  279. of
  280. <question-mark>
  281. characters (\c
  282. .BR \(dq??\(dq )
  283. shall address the previous line for which the line excluding the
  284. terminating
  285. <newline>
  286. matches the last BRE encountered. In addition, the second
  287. <question-mark>
  288. can be omitted at the end of a command line. Within the
  289. BRE, a
  290. <backslash>-\c
  291. <question-mark>
  292. pair (\c
  293. .BR \(dq\e?\(dq )
  294. shall represent a literal
  295. <question-mark>
  296. instead of the BRE delimiter. If necessary, the search shall wrap around
  297. to the end of the buffer and continue up to and including the current
  298. line, so that the entire buffer is searched.
  299. .IP " 7." 4
  300. A
  301. <plus-sign>
  302. (\c
  303. .BR '\(pl' )
  304. or
  305. <hyphen-minus>
  306. character (\c
  307. .BR '\-' )
  308. followed by a decimal number shall address the current line plus or
  309. minus the number. A
  310. <plus-sign>
  311. or
  312. <hyphen-minus>
  313. character not followed by a decimal number shall address the current
  314. line plus or minus 1.
  315. .P
  316. Addresses can be followed by zero or more address offsets, optionally
  317. <blank>-separated.
  318. Address offsets are constructed as follows:
  319. .IP " *" 4
  320. A
  321. <plus-sign>
  322. or
  323. <hyphen-minus>
  324. character followed by a decimal number shall add or subtract,
  325. respectively, the indicated number of lines to or from the address. A
  326. <plus-sign>
  327. or
  328. <hyphen-minus>
  329. character not followed by a decimal number shall add or subtract 1 to
  330. or from the address.
  331. .IP " *" 4
  332. A decimal number shall add the indicated number of lines to the
  333. address.
  334. .P
  335. It shall not be an error for an intermediate address value to be less
  336. than zero or greater than the last line in the edit buffer. It shall be
  337. an error for the final address value to be less than zero or greater
  338. than the last line in the edit buffer. It shall be an error if a search
  339. for a BRE fails to find a matching line.
  340. .P
  341. Commands accept zero, one, or two addresses. If more than the required
  342. number of addresses are provided to a command that requires zero
  343. addresses, it shall be an error. Otherwise, if more than the required
  344. number of addresses are provided to a command, the addresses specified
  345. first shall be evaluated and then discarded until the maximum number of
  346. valid addresses remain, for the specified command.
  347. .P
  348. Addresses shall be separated from each other by a
  349. <comma>
  350. (\c
  351. .BR ',' )
  352. or
  353. <semicolon>
  354. character (\c
  355. .BR ';' ).
  356. In the case of a
  357. <semicolon>
  358. separator, the current line (\c
  359. .BR '.' )
  360. shall be set to the first address, and only then will the second
  361. address be calculated. This feature can be used to determine the
  362. starting line for forwards and backwards searches; see rules 5. and
  363. 6.
  364. .P
  365. Addresses can be omitted on either side of the
  366. <comma>
  367. or
  368. <semicolon>
  369. separator, in which case the resulting address pairs shall be as
  370. follows:
  371. .TS
  372. center box tab(!);
  373. cB | cB
  374. lf5 | lf5.
  375. Specified!Resulting
  376. _
  377. \&,!1 , $
  378. \&, addr!1 , addr
  379. addr ,!addr , addr
  380. ;!. ; $
  381. ; addr!. ; addr
  382. addr ;!addr ; addr
  383. .TE
  384. .P
  385. Any
  386. <blank>
  387. characters included between addresses, address separators, or address
  388. offsets shall be ignored.
  389. .SS "Commands in ed"
  390. .P
  391. In the following list of
  392. .IR ed
  393. commands, the default addresses are shown in parentheses. The number of
  394. addresses shown in the default shall be the number expected by the
  395. command. The parentheses are not part of the address; they show that
  396. the given addresses are the default.
  397. .P
  398. It is generally invalid for more than one command to appear on a line.
  399. However, any command (except
  400. .BR e ,
  401. .BR E ,
  402. .BR f ,
  403. .BR q ,
  404. .BR Q ,
  405. .BR r ,
  406. .BR w ,
  407. and
  408. .BR ! )
  409. can be suffixed by the letter
  410. .BR l ,
  411. .BR n ,
  412. or
  413. .BR p ;
  414. in which case, except for the
  415. .BR l ,
  416. .BR n ,
  417. and
  418. .BR p
  419. commands, the command shall be executed and then the new current line
  420. shall be written as described below under the
  421. .BR l ,
  422. .BR n ,
  423. and
  424. .BR p
  425. commands. When an
  426. .BR l ,
  427. .BR n ,
  428. or
  429. .BR p
  430. suffix is used with an
  431. .BR l ,
  432. .BR n ,
  433. or
  434. .BR p
  435. command, the command shall write to standard output as described below,
  436. but it is unspecified whether the suffix writes the current line again
  437. in the requested format or whether the suffix has no effect. For
  438. example, the
  439. .BR pl
  440. command (base
  441. .BR p
  442. command with an
  443. .BR l
  444. suffix) shall either write just the current line or write it
  445. twice\(emonce as specified for
  446. .BR p
  447. and once as specified for
  448. .BR l .
  449. Also, the
  450. .BR g ,
  451. .BR G ,
  452. .BR v ,
  453. and
  454. .BR V
  455. commands shall take a command as a parameter.
  456. .P
  457. Each address component can be preceded by zero or more
  458. <blank>
  459. characters. The command letter can be preceded by zero or more
  460. <blank>
  461. characters. If a suffix letter (\c
  462. .BR l ,
  463. .BR n ,
  464. or
  465. .BR p )
  466. is given, the application shall ensure that it immediately follows the
  467. command.
  468. .P
  469. The
  470. .BR e ,
  471. .BR E ,
  472. .BR f ,
  473. .BR r ,
  474. and
  475. .BR w
  476. commands shall take an optional
  477. .IR file
  478. parameter, separated from the command letter by one or more
  479. <blank>
  480. characters.
  481. .P
  482. If changes have been made in the buffer since the last
  483. .BR w
  484. command that wrote the entire buffer,
  485. .IR ed
  486. shall warn the user if an attempt is made to destroy the editor buffer
  487. via the
  488. .BR e
  489. or
  490. .BR q
  491. commands. The
  492. .IR ed
  493. utility shall write the string:
  494. .sp
  495. .RS 4
  496. .nf
  497. "?\en"
  498. .fi
  499. .P
  500. .RE
  501. .P
  502. (followed by an explanatory message if
  503. .IR "help mode"
  504. has been enabled via the
  505. .BR H
  506. command) to standard output and shall continue in command mode with the
  507. current line number unchanged. If the
  508. .BR e
  509. or
  510. .BR q
  511. command is repeated with no intervening command, it shall take effect.
  512. .P
  513. If a terminal disconnect (see the Base Definitions volume of POSIX.1\(hy2017,
  514. .IR "Chapter 11" ", " "General Terminal Interface",
  515. Modem Disconnect and Closing a Device Terminal), is detected:
  516. .IP " *" 4
  517. If accompanied by a SIGHUP signal, the
  518. .IR ed
  519. utility shall operate as described in the ASYNCHRONOUS EVENTS section
  520. for a SIGHUP signal.
  521. .IP " *" 4
  522. If not accompanied by a SIGHUP signal, the
  523. .IR ed
  524. utility shall act as if an end-of-file had been detected on standard
  525. input.
  526. .P
  527. If an end-of-file is detected on standard input:
  528. .IP " *" 4
  529. If the
  530. .IR ed
  531. utility is in input mode,
  532. .IR ed
  533. shall terminate input mode and return to command mode. It is
  534. unspecified if any partially entered lines (that is, input text without
  535. a terminating
  536. <newline>)
  537. are discarded from the input text.
  538. .IP " *" 4
  539. If the
  540. .IR ed
  541. utility is in command mode, it shall act as if a
  542. .BR q
  543. command had been entered.
  544. .P
  545. If the closing delimiter of an RE or of a replacement string (for
  546. example,
  547. .BR '/' )
  548. in a
  549. .BR g ,
  550. .BR G ,
  551. .BR s ,
  552. .BR v ,
  553. or
  554. .BR V
  555. command would be the last character before a
  556. <newline>,
  557. that delimiter can be omitted, in which case the addressed line shall
  558. be written. For example, the following pairs of commands are
  559. equivalent:
  560. .sp
  561. .RS 4
  562. .nf
  563. s/s1/s2 s/s1/s2/p
  564. g/s1 g/s1/p
  565. ?s1 ?s1?
  566. .fi
  567. .P
  568. .RE
  569. .P
  570. If an invalid command is entered,
  571. .IR ed
  572. shall write the string:
  573. .sp
  574. .RS 4
  575. .nf
  576. "?\en"
  577. .fi
  578. .P
  579. .RE
  580. .P
  581. (followed by an explanatory message if
  582. .IR "help mode"
  583. has been enabled via the
  584. .BR H
  585. command) to standard output and shall continue in command mode with the
  586. current line number unchanged.
  587. .SS "Append Command"
  588. .IP "\fISynopsis\fR:" 10
  589. .sp -1v
  590. .RS 10
  591. .sp
  592. .RS 4
  593. .nf
  594. (.)a
  595. <\fItext\fR>
  596. \&.
  597. .fi
  598. .P
  599. .RE
  600. .RE
  601. .P
  602. The
  603. .BR a
  604. command shall read the given text and append it after the addressed
  605. line; the current line number shall become the address of the last
  606. inserted line or, if there were none, the addressed line. Address 0
  607. shall be valid for this command; it shall cause the appended text to be
  608. placed at the beginning of the buffer.
  609. .SS "Change Command"
  610. .IP "\fISynopsis\fR:" 10
  611. .sp -1v
  612. .RS 10
  613. .sp
  614. .RS 4
  615. .nf
  616. (.,.)c
  617. <\fItext\fR>
  618. \&.
  619. .fi
  620. .P
  621. .RE
  622. .RE
  623. .P
  624. The
  625. .BR c
  626. command shall delete the addressed lines, then accept input text that
  627. replaces these lines; the current line shall be set to the address of
  628. the last line input; or, if there were none, at the line after the last
  629. line deleted; if the lines deleted were originally at the end of the
  630. buffer, the current line number shall be set to the address of the new
  631. last line; if no lines remain in the buffer, the current line number
  632. shall be set to zero. Address 0 shall be valid for this command; it
  633. shall be interpreted as if address 1 were specified.
  634. .SS "Delete Command"
  635. .IP "\fISynopsis\fR:" 10
  636. .sp -1v
  637. .RS 10
  638. .sp
  639. .RS 4
  640. .nf
  641. (.,.)d
  642. .fi
  643. .P
  644. .RE
  645. .RE
  646. .P
  647. The
  648. .BR d
  649. command shall delete the addressed lines from the buffer. The address
  650. of the line after the last line deleted shall become the current line
  651. number; if the lines deleted were originally at the end of the buffer,
  652. the current line number shall be set to the address of the new last
  653. line; if no lines remain in the buffer, the current line number shall
  654. be set to zero.
  655. .SS "Edit Command"
  656. .IP "\fISynopsis\fR:" 10
  657. .sp -1v
  658. .RS 10
  659. .sp
  660. .RS 4
  661. .nf
  662. e \fB[\fIfile\fB]\fR
  663. .fi
  664. .P
  665. .RE
  666. .RE
  667. .P
  668. The
  669. .BR e
  670. command shall delete the entire contents of the buffer and then read in
  671. the file named by the pathname
  672. .IR file .
  673. The current line number shall be set to the address of the last line of
  674. the buffer. If no pathname is given, the currently remembered pathname,
  675. if any, shall be used (see the
  676. .BR f
  677. command). The number of bytes read shall be written to standard output,
  678. unless the
  679. .BR \-s
  680. option was specified, in the following format:
  681. .sp
  682. .RS 4
  683. .nf
  684. "%d\en", <\fInumber of bytes read\fR>
  685. .fi
  686. .P
  687. .RE
  688. .P
  689. The name \fIfile\fR shall be remembered for possible use as a default
  690. pathname in subsequent
  691. .BR e ,
  692. .BR E ,
  693. .BR r ,
  694. and
  695. .BR w
  696. commands. If
  697. .IR file
  698. is replaced by
  699. .BR '!' ,
  700. the rest of the line shall be taken to be a shell command line whose
  701. output is to be read. Such a shell command line shall not be remembered
  702. as the current
  703. .IR file .
  704. All marks shall be discarded upon the completion of a successful
  705. .BR e
  706. command. If the buffer has changed since the last time the entire
  707. buffer was written, the user shall be warned, as described previously.
  708. .SS "Edit Without Checking Command"
  709. .IP "\fISynopsis\fR:" 10
  710. .sp -1v
  711. .RS 10
  712. .sp
  713. .RS 4
  714. .nf
  715. E \fB[\fIfile\fB]\fR
  716. .fi
  717. .P
  718. .RE
  719. .RE
  720. .P
  721. The
  722. .BR E
  723. command shall possess all properties and restrictions of the
  724. .BR e
  725. command except that the editor shall not check to see whether any
  726. changes have been made to the buffer since the last
  727. .BR w
  728. command.
  729. .SS "Filename Command"
  730. .IP "\fISynopsis\fR:" 10
  731. .sp -1v
  732. .RS 10
  733. .sp
  734. .RS 4
  735. .nf
  736. f \fB[\fIfile\fB]\fR
  737. .fi
  738. .P
  739. .RE
  740. .RE
  741. .P
  742. If
  743. .IR file
  744. is given, the
  745. .BR f
  746. command shall change the currently remembered pathname to
  747. .IR file ;
  748. whether the name is changed or not, it shall then write the (possibly
  749. new) currently remembered pathname to the standard output in the
  750. following format:
  751. .sp
  752. .RS 4
  753. .nf
  754. "%s\en", <\fIpathname\fR>
  755. .fi
  756. .P
  757. .RE
  758. .P
  759. The current line number shall be unchanged.
  760. .SS "Global Command"
  761. .IP "\fISynopsis\fR:" 10
  762. .sp -1v
  763. .RS 10
  764. .sp
  765. .RS 4
  766. .nf
  767. (1,$)g/\fIRE\fR/\fIcommand list\fR
  768. .fi
  769. .P
  770. .RE
  771. .RE
  772. .P
  773. In the
  774. .BR g
  775. command, the first step shall be to mark every line for which the
  776. line excluding the terminating
  777. <newline>
  778. matches the given RE. Then, going sequentially from the beginning of
  779. the file to the end of the file, the given
  780. .IR "command list"
  781. shall be executed for each marked line, with the current line number
  782. set to the address of that line. Any line modified by the
  783. .IR "command list"
  784. shall be unmarked. When the
  785. .BR g
  786. command completes, the current line number shall have the value
  787. assigned by the last command in the
  788. .IR "command list" .
  789. If there were no matching lines, the current line number shall not be
  790. changed. A single command or the first of a list of commands shall
  791. appear on the same line as the global command. All lines of a
  792. multi-line list except the last line shall be ended with a
  793. <backslash>
  794. preceding the terminating
  795. <newline>;
  796. the
  797. .BR a ,
  798. .BR i ,
  799. and
  800. .BR c
  801. commands and associated input are permitted. The
  802. .BR '.'
  803. terminating input mode can be omitted if it would be the last line of
  804. the \fIcommand list\fR. An empty \fIcommand list\fR shall be equivalent
  805. to the
  806. .BR p
  807. command. The use of the
  808. .BR g ,
  809. .BR G ,
  810. .BR v ,
  811. .BR V ,
  812. and
  813. .BR !
  814. commands in the
  815. .IR "command list"
  816. produces undefined results. Any character other than
  817. <space>
  818. or
  819. <newline>
  820. can be used instead of a
  821. <slash>
  822. to delimit the RE. Within the RE, the RE delimiter itself can be used
  823. as a literal character if it is preceded by a
  824. <backslash>.
  825. .SS "Interactive Global Command"
  826. .IP "\fISynopsis\fR:" 10
  827. .sp -1v
  828. .RS 10
  829. .sp
  830. .RS 4
  831. .nf
  832. (1,$)G/\fIRE\fR/
  833. .fi
  834. .P
  835. .RE
  836. .RE
  837. .P
  838. In the
  839. .BR G
  840. command, the first step shall be to mark every line for which the line
  841. excluding the terminating
  842. <newline>
  843. matches the given RE. Then, for every such line, that line shall be
  844. written, the current line number shall be set to the address of that
  845. line, and any one command (other than one of the
  846. .BR a ,
  847. .BR c ,
  848. .BR i ,
  849. .BR g ,
  850. .BR G ,
  851. .BR v ,
  852. and
  853. .BR V
  854. commands) shall be read and executed. A
  855. <newline>
  856. shall act as a null command (causing no action to be taken on
  857. the current line); an
  858. .BR '&'
  859. shall cause the re-execution of the most recent non-null command
  860. executed within the current invocation of
  861. .BR G .
  862. Note that the commands input as part of the execution of the
  863. .BR G
  864. command can address and affect any lines in the buffer. Any line
  865. modified by the command shall be unmarked. The final value
  866. of the current line number shall be the value set by the last command
  867. successfully executed. (Note that the last command successfully
  868. executed shall be the
  869. .BR G
  870. command itself if a command fails or the null command is specified.) If
  871. there were no matching lines, the current line number shall not be
  872. changed. The
  873. .BR G
  874. command can be terminated by a SIGINT signal. Any character other than
  875. <space>
  876. or
  877. <newline>
  878. can be used instead of a
  879. <slash>
  880. to delimit the RE and the replacement. Within the RE, the RE delimiter
  881. itself can be used as a literal character if it is preceded by a
  882. <backslash>.
  883. .SS "Help Command"
  884. .IP "\fISynopsis\fR:" 10
  885. .sp -1v
  886. .RS 10
  887. .sp
  888. .RS 4
  889. .nf
  890. h
  891. .fi
  892. .P
  893. .RE
  894. .RE
  895. .P
  896. The
  897. .BR h
  898. command shall write a short message to standard output that explains
  899. the reason for the most recent
  900. .BR '?'
  901. notification. The current line number shall be unchanged.
  902. .SS "Help-Mode Command"
  903. .IP "\fISynopsis\fR:" 10
  904. .sp -1v
  905. .RS 10
  906. .sp
  907. .RS 4
  908. .nf
  909. H
  910. .fi
  911. .P
  912. .RE
  913. .RE
  914. .P
  915. The
  916. .BR H
  917. command shall cause
  918. .IR ed
  919. to enter a mode in which help messages (see the
  920. .BR h
  921. command) shall be written to standard output for all subsequent
  922. .BR '?'
  923. notifications. The
  924. .BR H
  925. command alternately shall turn this mode on and off; it is initially
  926. off. If the help-mode is being turned on, the
  927. .BR H
  928. command also explains the previous
  929. .BR '?'
  930. notification, if there was one. The current line number shall be
  931. unchanged.
  932. .SS "Insert Command"
  933. .IP "\fISynopsis\fR:" 10
  934. .sp -1v
  935. .RS 10
  936. .sp
  937. .RS 4
  938. .nf
  939. (.)i
  940. <\fItext\fR>
  941. \&.
  942. .fi
  943. .P
  944. .RE
  945. .RE
  946. .P
  947. The
  948. .BR i
  949. command shall insert the given text before the addressed line; the
  950. current line is set to the last inserted line or, if there was none, to
  951. the addressed line. This command differs from the
  952. .BR a
  953. command only in the placement of the input text. Address 0 shall be
  954. valid for this command; it shall be interpreted as if address 1 were
  955. specified.
  956. .SS "Join Command"
  957. .IP "\fISynopsis\fR:" 10
  958. .sp -1v
  959. .RS 10
  960. .sp
  961. .RS 4
  962. .nf
  963. (.,.+1)j
  964. .fi
  965. .P
  966. .RE
  967. .RE
  968. .P
  969. The
  970. .BR j
  971. command shall join contiguous lines by removing the appropriate
  972. <newline>
  973. characters. If exactly one address is given, this command shall do
  974. nothing. If lines are joined, the current line number shall be set to
  975. the address of the joined line; otherwise, the current line number shall
  976. be unchanged.
  977. .SS "Mark Command"
  978. .IP "\fISynopsis\fR:" 10
  979. .sp -1v
  980. .RS 10
  981. .sp
  982. .RS 4
  983. .nf
  984. (.)k\fIx\fR
  985. .fi
  986. .P
  987. .RE
  988. .RE
  989. .P
  990. The
  991. .BR k
  992. command shall mark the addressed line with name
  993. .IR x ,
  994. which the application shall ensure is a lowercase letter from the
  995. portable character set. The address
  996. .BR \(dq\(aqx\(dq
  997. shall then refer to this line; the current line number shall be
  998. unchanged.
  999. .SS "List Command"
  1000. .IP "\fISynopsis\fR:" 10
  1001. .sp -1v
  1002. .RS 10
  1003. .sp
  1004. .RS 4
  1005. .nf
  1006. (.,.)l
  1007. .fi
  1008. .P
  1009. .RE
  1010. .RE
  1011. .P
  1012. The
  1013. .BR l
  1014. command shall write to standard output the addressed lines in a
  1015. visually unambiguous form. The characters listed in the Base Definitions volume of POSIX.1\(hy2017,
  1016. .IR "Table 5-1" ", " "Escape Sequences and Associated Actions"
  1017. (\c
  1018. .BR '\e\e' ,
  1019. .BR '\ea' ,
  1020. .BR '\eb' ,
  1021. .BR '\ef' ,
  1022. .BR '\er' ,
  1023. .BR '\et' ,
  1024. .BR '\ev' )
  1025. shall be written as the corresponding escape sequence; the
  1026. .BR '\en'
  1027. in that table is not applicable. Non-printable characters not in the
  1028. table shall be written as one three-digit octal number (with a
  1029. preceding
  1030. <backslash>
  1031. character) for each byte in the character (most significant byte first).
  1032. .P
  1033. Long lines shall be folded, with the point of folding indicated by
  1034. <newline>
  1035. preceded by a
  1036. <backslash>;
  1037. the length at which folding occurs is unspecified, but should be
  1038. appropriate for the output device. The end of each line shall be marked
  1039. with a
  1040. .BR '$' ,
  1041. and
  1042. .BR '$'
  1043. characters within the text shall be written with a preceding
  1044. <backslash>.
  1045. An
  1046. .BR l
  1047. command can be appended to any other command other than
  1048. .BR e ,
  1049. .BR E ,
  1050. .BR f ,
  1051. .BR q ,
  1052. .BR Q ,
  1053. .BR r ,
  1054. .BR w ,
  1055. or
  1056. .BR ! .
  1057. The current line number shall be set to the address of the last line
  1058. written.
  1059. .SS "Move Command"
  1060. .IP "\fISynopsis\fR:" 10
  1061. .sp -1v
  1062. .RS 10
  1063. .sp
  1064. .RS 4
  1065. .nf
  1066. (.,.)m\fIaddress\fR
  1067. .fi
  1068. .P
  1069. .RE
  1070. .RE
  1071. .P
  1072. The
  1073. .BR m
  1074. command shall reposition the addressed lines after the line addressed
  1075. by
  1076. .IR address .
  1077. Address 0 shall be valid for
  1078. .IR address
  1079. and cause the addressed lines to be moved to the beginning of the
  1080. buffer. It shall be an error if address
  1081. .IR address
  1082. falls within the range of moved lines. The current line number shall be
  1083. set to the address of the last line moved.
  1084. .SS "Number Command"
  1085. .IP "\fISynopsis\fR:" 10
  1086. .sp -1v
  1087. .RS 10
  1088. .sp
  1089. .RS 4
  1090. .nf
  1091. (.,.)n
  1092. .fi
  1093. .P
  1094. .RE
  1095. .RE
  1096. .P
  1097. The
  1098. .BR n
  1099. command shall write to standard output the addressed lines, preceding
  1100. each line by its line number and a
  1101. <tab>;
  1102. the current line number shall be set to the address of the last line
  1103. written. The
  1104. .BR n
  1105. command can be appended to any command other than
  1106. .BR e ,
  1107. .BR E ,
  1108. .BR f ,
  1109. .BR q ,
  1110. .BR Q ,
  1111. .BR r ,
  1112. .BR w ,
  1113. or
  1114. .BR ! .
  1115. .SS "Print Command"
  1116. .IP "\fISynopsis\fR:" 10
  1117. .sp -1v
  1118. .RS 10
  1119. .sp
  1120. .RS 4
  1121. .nf
  1122. (.,.)p
  1123. .fi
  1124. .P
  1125. .RE
  1126. .RE
  1127. .P
  1128. The
  1129. .BR p
  1130. command shall write to standard output the addressed lines; the current
  1131. line number shall be set to the address of the last line written. The
  1132. .BR p
  1133. command can be appended to any command other than
  1134. .BR e ,
  1135. .BR E ,
  1136. .BR f ,
  1137. .BR q ,
  1138. .BR Q ,
  1139. .BR r ,
  1140. .BR w ,
  1141. or
  1142. .BR ! .
  1143. .SS "Prompt Command"
  1144. .IP "\fISynopsis\fR:" 10
  1145. .sp -1v
  1146. .RS 10
  1147. .sp
  1148. .RS 4
  1149. .nf
  1150. P
  1151. .fi
  1152. .P
  1153. .RE
  1154. .RE
  1155. .P
  1156. The
  1157. .BR P
  1158. command shall cause
  1159. .IR ed
  1160. to prompt with an
  1161. <asterisk>
  1162. (\c
  1163. .BR '*' )
  1164. (or
  1165. .IR string ,
  1166. if
  1167. .BR \-p
  1168. is specified) for all subsequent commands. The
  1169. .BR P
  1170. command alternatively shall turn this mode on and off; it shall be
  1171. initially on if the
  1172. .BR \-p
  1173. option is specified; otherwise, off. The current line number shall be
  1174. unchanged.
  1175. .SS "Quit Command"
  1176. .IP "\fISynopsis\fR:" 10
  1177. .sp -1v
  1178. .RS 10
  1179. .sp
  1180. .RS 4
  1181. .nf
  1182. q
  1183. .fi
  1184. .P
  1185. .RE
  1186. .RE
  1187. .P
  1188. The
  1189. .BR q
  1190. command shall cause
  1191. .IR ed
  1192. to exit. If the buffer has changed since the last time the entire
  1193. buffer was written, the user shall be warned, as described previously.
  1194. .SS "Quit Without Checking Command"
  1195. .IP "\fISynopsis\fR:" 10
  1196. .sp -1v
  1197. .RS 10
  1198. .sp
  1199. .RS 4
  1200. .nf
  1201. Q
  1202. .fi
  1203. .P
  1204. .RE
  1205. .RE
  1206. .P
  1207. The
  1208. .BR Q
  1209. command shall cause
  1210. .IR ed
  1211. to exit without checking whether changes have been made in the buffer
  1212. since the last
  1213. .BR w
  1214. command.
  1215. .SS "Read Command"
  1216. .IP "\fISynopsis\fR:" 10
  1217. .sp -1v
  1218. .RS 10
  1219. .sp
  1220. .RS 4
  1221. .nf
  1222. ($)r\fB [\fIfile\fB]\fR
  1223. .fi
  1224. .P
  1225. .RE
  1226. .RE
  1227. .P
  1228. The
  1229. .BR r
  1230. command shall read in the file named by the pathname
  1231. .IR file
  1232. and append it after the addressed line. If no
  1233. .IR file
  1234. argument is given, the currently remembered pathname, if any, shall be
  1235. used (see the
  1236. .BR e
  1237. and
  1238. .BR f
  1239. commands). The currently remembered pathname shall not be changed
  1240. unless there is no remembered pathname. Address 0 shall be valid for
  1241. .BR r
  1242. and shall cause the file to be read at the beginning of the buffer. If
  1243. the read is successful, and
  1244. .BR \-s
  1245. was not specified, the number of bytes read shall be written to
  1246. standard output in the following format:
  1247. .sp
  1248. .RS 4
  1249. .nf
  1250. "%d\en", <\fInumber of bytes read\fR>
  1251. .fi
  1252. .P
  1253. .RE
  1254. .P
  1255. The current line number shall be set to the address of the last line
  1256. read in. If
  1257. .IR file
  1258. is replaced by
  1259. .BR '!' ,
  1260. the rest of the line shall be taken to be a shell command line whose
  1261. output is to be read. Such a shell command line shall not be remembered
  1262. as the current pathname.
  1263. .SS "Substitute Command"
  1264. .IP "\fISynopsis\fR:" 10
  1265. .sp -1v
  1266. .RS 10
  1267. .sp
  1268. .RS 4
  1269. .nf
  1270. (.,.)s/\fIRE\fR/\fIreplacement\fR/\fIflags\fR
  1271. .fi
  1272. .P
  1273. .RE
  1274. .RE
  1275. .P
  1276. The
  1277. .BR s
  1278. command shall search each addressed line for an occurrence of the
  1279. specified RE and replace either the first or all (non-overlapped)
  1280. matched strings with the
  1281. .IR replacement ;
  1282. see the following description of the
  1283. .BR g
  1284. suffix. It is an error if the substitution fails on every addressed
  1285. line. Any character other than
  1286. <space>
  1287. or
  1288. <newline>
  1289. can be used instead of a
  1290. <slash>
  1291. to delimit the RE and the replacement. Within the RE, the RE delimiter
  1292. itself can be used as a literal character if it is preceded by a
  1293. <backslash>.
  1294. The current line shall be set to the address of the last line on which
  1295. a substitution occurred.
  1296. .P
  1297. An
  1298. <ampersand>
  1299. (\c
  1300. .BR '&' )
  1301. appearing in the
  1302. .IR replacement
  1303. shall be replaced by the string matching the RE on the current line.
  1304. The special meaning of
  1305. .BR '&'
  1306. in this context can be suppressed by preceding it by
  1307. <backslash>.
  1308. As a more general feature, the characters
  1309. .BR '\en' ,
  1310. where
  1311. .IR n
  1312. is a digit, shall be replaced by the text matched by the corresponding
  1313. back-reference expression. If the corresponding back-reference
  1314. expression does not match, then the characters
  1315. .BR '\en'
  1316. shall be replaced by the empty string. When the character
  1317. .BR '%'
  1318. is the only character in the
  1319. .IR replacement ,
  1320. the
  1321. .IR replacement
  1322. used in the most recent substitute command shall be used as the
  1323. .IR replacement
  1324. in the current substitute command; if there was no previous substitute
  1325. command, the use of
  1326. .BR '%'
  1327. in this manner shall be an error. The
  1328. .BR '%'
  1329. shall lose its special meaning when it is in a replacement string of
  1330. more than one character or is preceded by a
  1331. <backslash>.
  1332. For each
  1333. <backslash>
  1334. encountered in scanning
  1335. .IR replacement
  1336. from beginning to end, the following character shall lose its special
  1337. meaning (if any). It is unspecified what special meaning is given to
  1338. any character other than
  1339. <backslash>,
  1340. .BR '&' ,
  1341. .BR '%' ,
  1342. or digits.
  1343. .P
  1344. A line can be split by substituting a
  1345. <newline>
  1346. into it. The application shall ensure it escapes the
  1347. <newline>
  1348. in the
  1349. .IR replacement
  1350. by preceding it by
  1351. <backslash>.
  1352. Such substitution cannot be done as part of a
  1353. .BR g
  1354. or
  1355. .BR v
  1356. .IR "command list" .
  1357. The current line number shall be set to the address of the last line on
  1358. which a substitution is performed. If no substitution is performed, the
  1359. current line number shall be unchanged. If a line is split, a
  1360. substitution shall be considered to have been performed on each of the
  1361. new lines for the purpose of determining the new current line number. A
  1362. substitution shall be considered to have been performed even if the
  1363. replacement string is identical to the string that it replaces.
  1364. .P
  1365. The application shall ensure that the value of
  1366. .IR flags
  1367. is zero or more of:
  1368. .IP "\fIcount\fR" 8
  1369. Substitute for the
  1370. .IR count th
  1371. occurrence only of the RE found on each addressed line.
  1372. .IP "\fBg\fR" 8
  1373. Globally substitute for all non-overlapping instances of the RE rather
  1374. than just the first one. If both
  1375. .BR g
  1376. and
  1377. .IR count
  1378. are specified, the results are unspecified.
  1379. .IP "\fBl\fR" 8
  1380. Write to standard output the final line in which a substitution was
  1381. made. The line shall be written in the format specified for the
  1382. .BR l
  1383. command.
  1384. .IP "\fBn\fR" 8
  1385. Write to standard output the final line in which a substitution was
  1386. made. The line shall be written in the format specified for the
  1387. .BR n
  1388. command.
  1389. .IP "\fBp\fR" 8
  1390. Write to standard output the final line in which a substitution was
  1391. made. The line shall be written in the format specified for the
  1392. .BR p
  1393. command.
  1394. .SS "Copy Command"
  1395. .IP "\fISynopsis\fR:" 10
  1396. .sp -1v
  1397. .RS 10
  1398. .sp
  1399. .RS 4
  1400. .nf
  1401. (.,.)t\fIaddress\fR
  1402. .fi
  1403. .P
  1404. .RE
  1405. .RE
  1406. .P
  1407. The
  1408. .BR t
  1409. command shall be equivalent to the
  1410. .BR m
  1411. command, except that a copy of the addressed lines shall be placed
  1412. after address
  1413. .IR address
  1414. (which can be 0); the current line number shall be set to the address
  1415. of the last line added.
  1416. .SS "Undo Command"
  1417. .IP "\fISynopsis\fR:" 10
  1418. .sp -1v
  1419. .RS 10
  1420. .sp
  1421. .RS 4
  1422. .nf
  1423. u
  1424. .fi
  1425. .P
  1426. .RE
  1427. .RE
  1428. .P
  1429. The
  1430. .BR u
  1431. command shall nullify the effect of the most recent command that
  1432. modified anything in the buffer, namely the most recent
  1433. .BR a ,
  1434. .BR c ,
  1435. .BR d ,
  1436. .BR g ,
  1437. .BR i ,
  1438. .BR j ,
  1439. .BR m ,
  1440. .BR r ,
  1441. .BR s ,
  1442. .BR t ,
  1443. .BR u ,
  1444. .BR v ,
  1445. .BR G ,
  1446. or
  1447. .BR V
  1448. command. All changes made to the buffer by a
  1449. .BR g ,
  1450. .BR G ,
  1451. .BR v ,
  1452. or
  1453. .BR V
  1454. global command shall be undone as a single change; if no changes were
  1455. made by the global command (such as with
  1456. .BR g /RE/\c
  1457. .BR p ),
  1458. the
  1459. .BR u
  1460. command shall have no effect. The current line number shall be set to
  1461. the value it had immediately before the command being undone started.
  1462. .SS "Global Non-Matched Command"
  1463. .IP "\fISynopsis\fR:" 10
  1464. .sp -1v
  1465. .RS 10
  1466. .sp
  1467. .RS 4
  1468. .nf
  1469. (1,$)v\fR/\fIRE\fR/\fIcommand list\fR
  1470. .fi
  1471. .P
  1472. .RE
  1473. .RE
  1474. .P
  1475. This command shall be equivalent to the global command
  1476. .BR g
  1477. except that the lines that are marked during the first step shall be
  1478. those for which the line excluding the terminating
  1479. <newline>
  1480. does not match the RE.
  1481. .SS "Interactive Global Not-Matched Command"
  1482. .IP "\fISynopsis\fR:" 10
  1483. .sp -1v
  1484. .RS 10
  1485. .sp
  1486. .RS 4
  1487. .nf
  1488. (1,$)V\fR/\fIRE\fR/
  1489. .fi
  1490. .P
  1491. .RE
  1492. .RE
  1493. .P
  1494. This command shall be equivalent to the interactive global command
  1495. .BR G
  1496. except that the lines that are marked during the first step shall be
  1497. those for which the line excluding the terminating
  1498. <newline>
  1499. does not match the RE.
  1500. .SS "Write Command"
  1501. .IP "\fISynopsis\fR:" 10
  1502. .sp -1v
  1503. .RS 10
  1504. .sp
  1505. .RS 4
  1506. .nf
  1507. (1,$)w\fB [\fIfile\fB]
  1508. .fi
  1509. .P
  1510. .RE
  1511. .RE
  1512. .P
  1513. The
  1514. .BR w
  1515. command shall write the addressed lines into the file named by the
  1516. pathname
  1517. .IR file .
  1518. The command shall create the file, if it does not exist, or shall
  1519. replace the contents of the existing file. The currently remembered
  1520. pathname shall not be changed unless there is no remembered pathname.
  1521. If no pathname is given, the currently remembered pathname, if any,
  1522. shall be used (see the
  1523. .BR e
  1524. and
  1525. .BR f
  1526. commands); the current line number shall be unchanged. If the command
  1527. is successful, the number of bytes written shall be written to standard
  1528. output, unless the
  1529. .BR \-s
  1530. option was specified, in the following format:
  1531. .sp
  1532. .RS 4
  1533. .nf
  1534. "%d\en", <\fInumber of bytes written\fR>
  1535. .fi
  1536. .P
  1537. .RE
  1538. .P
  1539. If
  1540. .IR file
  1541. begins with
  1542. .BR '!' ,
  1543. the rest of the line shall be taken to be a shell command line whose
  1544. standard input shall be the addressed lines. Such a shell command line
  1545. shall not be remembered as the current pathname. This usage of the
  1546. write command with
  1547. .BR '!'
  1548. shall not be considered as a ``last
  1549. .BR w
  1550. command that wrote the entire buffer'', as described previously; thus,
  1551. this alone shall not prevent the warning to the user if an attempt is
  1552. made to destroy the editor buffer via the
  1553. .BR e
  1554. or
  1555. .BR q
  1556. commands.
  1557. .SS "Line Number Command"
  1558. .IP "\fISynopsis\fR:" 10
  1559. .sp -1v
  1560. .RS 10
  1561. .sp
  1562. .RS 4
  1563. .nf
  1564. ($)=
  1565. .fi
  1566. .P
  1567. .RE
  1568. .RE
  1569. .P
  1570. The line number of the addressed line shall be written to standard
  1571. output in the following format:
  1572. .sp
  1573. .RS 4
  1574. .nf
  1575. "%d\en", <\fIline number\fR>
  1576. .fi
  1577. .P
  1578. .RE
  1579. .P
  1580. The current line number shall be unchanged by this command.
  1581. .SS "Shell Escape Command"
  1582. .IP "\fISynopsis\fR:" 10
  1583. .sp -1v
  1584. .RS 10
  1585. .sp
  1586. .RS 4
  1587. .nf
  1588. !\fIcommand\fR
  1589. .fi
  1590. .P
  1591. .RE
  1592. .RE
  1593. .P
  1594. The remainder of the line after the
  1595. .BR '!'
  1596. shall be sent to the command interpreter to be interpreted as a shell
  1597. command line. Within the text of that shell command line, the unescaped
  1598. character
  1599. .BR '%'
  1600. shall be replaced with the remembered pathname; if a
  1601. .BR '!'
  1602. appears as the first character of the command, it shall be replaced
  1603. with the text of the previous shell command executed via
  1604. .BR '!' .
  1605. Thus,
  1606. .BR \(dq!!\(dq
  1607. shall repeat the previous !\fIcommand\fP. If any replacements of
  1608. .BR '%'
  1609. or
  1610. .BR '!'
  1611. are performed, the modified line shall be written to the standard
  1612. output before
  1613. .IR command
  1614. is executed. The
  1615. .BR !
  1616. command shall write:
  1617. .sp
  1618. .RS 4
  1619. .nf
  1620. "!\en"
  1621. .fi
  1622. .P
  1623. .RE
  1624. .P
  1625. to standard output upon completion, unless the
  1626. .BR \-s
  1627. option is specified. The current line number shall be unchanged.
  1628. .SS "Null Command"
  1629. .IP "\fISynopsis\fR:" 10
  1630. .sp -1v
  1631. .RS 10
  1632. .sp
  1633. .RS 4
  1634. .nf
  1635. (.+1)
  1636. .fi
  1637. .P
  1638. .RE
  1639. .RE
  1640. .P
  1641. An address alone on a line shall cause the addressed line to be
  1642. written. A
  1643. <newline>
  1644. alone shall be equivalent to
  1645. .BR \(dq+1p\(dq .
  1646. The current line number shall be set to the address of the written
  1647. line.
  1648. .SH "EXIT STATUS"
  1649. The following exit values shall be returned:
  1650. .IP "\00" 6
  1651. Successful completion without any file or command errors.
  1652. .IP >0 6
  1653. An error occurred.
  1654. .SH "CONSEQUENCES OF ERRORS"
  1655. When an error in the input script is encountered, or when an error is
  1656. detected that is a consequence of the data (not) present in the file or
  1657. due to an external condition such as a read or write error:
  1658. .IP " *" 4
  1659. If the standard input is a terminal device file, all input shall be
  1660. flushed, and a new command read.
  1661. .IP " *" 4
  1662. If the standard input is a regular file,
  1663. .IR ed
  1664. shall terminate with a non-zero exit status.
  1665. .LP
  1666. .IR "The following sections are informative."
  1667. .SH "APPLICATION USAGE"
  1668. Because of the extremely terse nature of the default error messages,
  1669. the prudent script writer begins the
  1670. .IR ed
  1671. input commands with an
  1672. .BR H
  1673. command, so that if any errors do occur at least some clue as to the
  1674. cause is made available.
  1675. .P
  1676. In earlier versions of this standard, an obsolescent
  1677. .BR \-
  1678. option was described. This is no longer specified. Applications should
  1679. use the
  1680. .BR \-s
  1681. option. Using
  1682. .BR \-
  1683. as a
  1684. .IR file
  1685. operand now produces unspecified results. This allows implementations
  1686. to continue to support the former required behavior.
  1687. .SH EXAMPLES
  1688. None.
  1689. .SH RATIONALE
  1690. The initial description of this utility was adapted from the SVID. It
  1691. contains some features not found in Version 7 or BSD-derived systems.
  1692. Some of the differences between the POSIX and BSD
  1693. .IR ed
  1694. utilities include, but need not be limited to:
  1695. .IP " *" 4
  1696. The BSD
  1697. .BR \-
  1698. option does not suppress the
  1699. .BR '!'
  1700. prompt after a
  1701. .BR !
  1702. command.
  1703. .IP " *" 4
  1704. BSD does not support the special meanings of the
  1705. .BR '%'
  1706. and
  1707. .BR '!'
  1708. characters within a
  1709. .BR !
  1710. command.
  1711. .IP " *" 4
  1712. BSD does not support the
  1713. .IR addresses
  1714. .BR ';'
  1715. and
  1716. .BR ',' .
  1717. .IP " *" 4
  1718. BSD allows the command/suffix pairs
  1719. .BR pp ,
  1720. .BR ll ,
  1721. and so on, which are unspecified in this volume of POSIX.1\(hy2017.
  1722. .IP " *" 4
  1723. BSD does not support the
  1724. .BR '!'
  1725. character part of the
  1726. .BR e ,
  1727. .BR r ,
  1728. or
  1729. .BR w
  1730. commands.
  1731. .IP " *" 4
  1732. A failed
  1733. .BR g
  1734. command in BSD sets the line number to the last line searched if there
  1735. are no matches.
  1736. .IP " *" 4
  1737. BSD does not default the
  1738. .IR "command list"
  1739. to the
  1740. .BR p
  1741. command.
  1742. .IP " *" 4
  1743. BSD does not support the
  1744. .BR G ,
  1745. .BR h ,
  1746. .BR H ,
  1747. .BR n ,
  1748. or
  1749. .BR V
  1750. commands.
  1751. .IP " *" 4
  1752. On BSD, if there is no inserted text, the insert command changes the
  1753. current line to the referenced line \-1; that is, the line before the
  1754. specified line.
  1755. .IP " *" 4
  1756. On BSD, the
  1757. .IR join
  1758. command with only a single address changes the current line to that
  1759. address.
  1760. .IP " *" 4
  1761. BSD does not support the
  1762. .BR P
  1763. command; moreover, in BSD it is synonymous with the
  1764. .BR p
  1765. command.
  1766. .IP " *" 4
  1767. BSD does not support the
  1768. .IR undo
  1769. of the commands
  1770. .BR j ,
  1771. .BR m ,
  1772. .BR r ,
  1773. .BR s ,
  1774. or
  1775. .BR t .
  1776. .IP " *" 4
  1777. The Version 7
  1778. .IR ed
  1779. command
  1780. .BR W ,
  1781. and the BSD
  1782. .IR ed
  1783. commands
  1784. .BR W ,
  1785. .BR wq ,
  1786. and
  1787. .BR z
  1788. are not present in this volume of POSIX.1\(hy2017.
  1789. .P
  1790. The
  1791. .BR \-s
  1792. option was added to allow the functionality of the removed
  1793. .BR \-
  1794. option in a manner compatible with the Utility Syntax Guidelines.
  1795. .P
  1796. In early proposals there was a limit,
  1797. {ED_FILE_MAX},
  1798. that described the historical limitations of some
  1799. .IR ed
  1800. utilities in their handling of large files; some of these have had
  1801. problems with files larger than 100\|000 bytes. It was this limitation
  1802. that prompted much of the desire to include a
  1803. .IR split
  1804. command in this volume of POSIX.1\(hy2017. Since this limit was removed, this volume of POSIX.1\(hy2017 requires that
  1805. implementations document the file size limits imposed by
  1806. .IR ed
  1807. in the conformance document. The limit
  1808. {ED_LINE_MAX}
  1809. was also removed; therefore, the global limit
  1810. {LINE_MAX}
  1811. is used for input and output lines.
  1812. .P
  1813. The manner in which the
  1814. .BR l
  1815. command writes non-printable characters was changed to avoid
  1816. the historical backspace-overstrike method. On video display terminals,
  1817. the overstrike is ambiguous because most terminals simply replace
  1818. overstruck characters, making the
  1819. .BR l
  1820. format not useful for its intended purpose of unambiguously
  1821. understanding the content of the line. The historical
  1822. <backslash>-escapes
  1823. were also ambiguous. (The string
  1824. .BR \(dqa\e0011\(dq
  1825. could represent a line containing those six characters or a line
  1826. containing the three characters
  1827. .BR 'a' ,
  1828. a byte with a binary value of 1, and a 1.) In the format required here,
  1829. a
  1830. <backslash>
  1831. appearing in the line is written as
  1832. .BR \(dq\e\e\(dq
  1833. so that the output is truly unambiguous. The method of marking the ends
  1834. of lines was adopted from the
  1835. .IR ex
  1836. editor and is required for any line ending in
  1837. <space>
  1838. characters; the
  1839. .BR '$'
  1840. is placed on all lines so that a real
  1841. .BR '$'
  1842. at the end of a line cannot be misinterpreted.
  1843. .P
  1844. Earlier versions of this standard allowed for implementations
  1845. with bytes other than eight bits, but this has been modified in this
  1846. version.
  1847. .P
  1848. The description of how a NUL is written was removed. The NUL character
  1849. cannot be in text files, and this volume of POSIX.1\(hy2017 should not dictate behavior in the
  1850. case of undefined, erroneous input.
  1851. .P
  1852. Unlike some of the other editing utilities, the filenames accepted by
  1853. the
  1854. .BR E ,
  1855. .BR e ,
  1856. .BR R ,
  1857. and
  1858. .BR r
  1859. commands are not patterns.
  1860. .P
  1861. Early proposals stated that the
  1862. .BR \-p
  1863. option worked only when standard input was associated with a terminal
  1864. device. This has been changed to conform to historical implementations,
  1865. thereby allowing applications to interpose themselves between a user
  1866. and the
  1867. .IR ed
  1868. utility.
  1869. .P
  1870. The form of the substitute command that uses the
  1871. .BR n
  1872. suffix was limited in some historical documentation (where this was
  1873. described incorrectly as ``backreferencing''). This limit has been
  1874. omitted because there is no reason why an editor processing lines of
  1875. {LINE_MAX}
  1876. length should have this restriction. The command
  1877. .BR "s/x/X/2047"
  1878. should be able to substitute the 2\|047th occurrence of
  1879. .BR 'x'
  1880. on a line.
  1881. .P
  1882. The use of printing commands with printing suffixes (such as
  1883. .BR pn ,
  1884. .BR lp ,
  1885. and so on) was made unspecified because BSD-based systems allow this,
  1886. whereas System V does not.
  1887. .P
  1888. Some BSD-based systems exit immediately upon receipt of end-of-file if
  1889. all of the lines in the file have been deleted. Since this volume of POSIX.1\(hy2017 refers
  1890. to the
  1891. .BR q
  1892. command in this instance, such behavior is not allowed.
  1893. .P
  1894. Some historical implementations returned exit status zero even if
  1895. command errors had occurred; this is not allowed by this volume of POSIX.1\(hy2017.
  1896. .P
  1897. Some historical implementations contained a bug that allowed a single
  1898. <period>
  1899. to be entered in input mode as
  1900. <backslash>
  1901. <period>
  1902. <newline>.
  1903. This is not allowed by
  1904. .IR ed
  1905. because there is no description of escaping any of the characters in
  1906. input mode;
  1907. <backslash>
  1908. characters are entered into the buffer exactly as typed. The typical
  1909. method of entering a single
  1910. <period>
  1911. has been to precede it with another character and then use the substitute
  1912. command to delete that character.
  1913. .P
  1914. It is difficult under some modes of some versions of historical
  1915. operating system terminal drivers to distinguish between an end-of-file
  1916. condition and terminal disconnect. POSIX.1\(hy2008 does not require
  1917. implementations to distinguish between the two situations, which
  1918. permits historical implementations of the
  1919. .IR ed
  1920. utility on historical platforms to conform. Implementations are
  1921. encouraged to distinguish between the two, if possible, and take
  1922. appropriate action on terminal disconnect.
  1923. .P
  1924. Historically,
  1925. .IR ed
  1926. accepted a zero address for the
  1927. .BR a
  1928. and
  1929. .BR r
  1930. commands in order to insert text at the start of the edit buffer. When
  1931. the buffer was empty the command
  1932. .BR .=
  1933. returned zero. POSIX.1\(hy2008 requires conformance to historical practice.
  1934. .P
  1935. For consistency with the
  1936. .BR a
  1937. and
  1938. .BR r
  1939. commands and better user functionality, the
  1940. .BR i
  1941. and
  1942. .BR c
  1943. commands must also accept an address of 0, in which case 0\fIi\fP is
  1944. treated as 1\fIi\fP and likewise for the
  1945. .BR c
  1946. command.
  1947. .P
  1948. All of the following are valid addresses:
  1949. .IP "\fR+++\fP" 12
  1950. Three lines after the current line.
  1951. .IP "\fR/\fIpattern\fR/\-\fR" 12
  1952. One line before the next occurrence of pattern.
  1953. .IP "\fR\-2\fR" 12
  1954. Two lines before the current line.
  1955. .IP "\fR3\ \-\|\-\|\-\|\-\ 2\fR" 12
  1956. Line one (note the intermediate negative address).
  1957. .IP "\fR1\ 2\ 3\fR" 12
  1958. Line six.
  1959. .P
  1960. Any number of addresses can be provided to commands taking addresses;
  1961. for example,
  1962. .BR \(dq1,2,3,4,5p\(dq
  1963. prints lines 4 and 5, because two is the greatest valid number of
  1964. addresses accepted by the
  1965. .BR print
  1966. command. This, in combination with the
  1967. <semicolon>
  1968. delimiter, permits users to create commands based on ordered patterns
  1969. in the file. For example, the command
  1970. .BR \(dq3;/foo/;+2p\(dq
  1971. will display the first line after line 3 that contains the pattern
  1972. .IR foo ,
  1973. plus the next two lines. Note that the address
  1974. .BR \(dq3;\(dq
  1975. must still be evaluated before being discarded, because the search
  1976. origin for the
  1977. .BR \(dq/foo/\(dq
  1978. command depends on this.
  1979. .P
  1980. Historically,
  1981. .IR ed
  1982. disallowed address chains, as discussed above, consisting solely of
  1983. <comma>
  1984. or
  1985. <semicolon>
  1986. separators; for example,
  1987. .BR \(dq,,,\(dq
  1988. or
  1989. .BR \(dq;;;\(dq
  1990. were considered an error. For consistency of address specification,
  1991. this restriction is removed. The following table lists some of the
  1992. address forms now possible:
  1993. .TS
  1994. center box tab(!);
  1995. cB | cB | cB | cB | cB
  1996. lf5 | nf5 | nf5 | l | l.
  1997. Address!Addr1!Addr2!Status!Comment
  1998. _
  1999. 7,!7!7!Historical
  2000. 7,5,!5!5!Historical
  2001. 7,5,9!5!9!Historical
  2002. 7,9!7!9!Historical
  2003. 7,+!7!8!Historical
  2004. \&,!1!$!Historical
  2005. \&,7!1!7!Extension
  2006. \&,,!$!$!Extension
  2007. \&,;!$!$!Extension
  2008. 7;!7!7!Historical
  2009. 7;5;!5!5!Historical
  2010. 7;5;9!5!9!Historical
  2011. 7;5,9!5!9!Historical
  2012. 7;$;4!$!4!Historical!Valid, but erroneous.
  2013. 7;9!7!9!Historical
  2014. 7;+!7!8!Historical
  2015. ;!.!$!Historical
  2016. ;7!.!7!Extension
  2017. ;;!$!$!Extension
  2018. ;,!$!$!Extension
  2019. .TE
  2020. .P
  2021. Historically,
  2022. .IR ed
  2023. accepted the
  2024. .BR '\(ha'
  2025. character as an address, in which case it was identical to the
  2026. <hyphen-minus>
  2027. character. POSIX.1\(hy2008 does not require or prohibit this behavior.
  2028. .SH "FUTURE DIRECTIONS"
  2029. None.
  2030. .SH "SEE ALSO"
  2031. .IR "Section 1.4" ", " "Utility Description Defaults",
  2032. .IR "\fIex\fR\^",
  2033. .IR "\fIsed\fR\^",
  2034. .IR "\fIsh\fR\^",
  2035. .IR "\fIvi\fR\^"
  2036. .P
  2037. The Base Definitions volume of POSIX.1\(hy2017,
  2038. .IR "Table 5-1" ", " "Escape Sequences and Associated Actions",
  2039. .IR "Chapter 8" ", " "Environment Variables",
  2040. .IR "Section 9.3" ", " "Basic Regular Expressions",
  2041. .IR "Chapter 11" ", " "General Terminal Interface",
  2042. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  2043. .\"
  2044. .SH COPYRIGHT
  2045. Portions of this text are reprinted and reproduced in electronic form
  2046. from IEEE Std 1003.1-2017, Standard for Information Technology
  2047. -- Portable Operating System Interface (POSIX), The Open Group Base
  2048. Specifications Issue 7, 2018 Edition,
  2049. Copyright (C) 2018 by the Institute of
  2050. Electrical and Electronics Engineers, Inc and The Open Group.
  2051. In the event of any discrepancy between this version and the original IEEE and
  2052. The Open Group Standard, the original IEEE and The Open Group Standard
  2053. is the referee document. The original Standard can be obtained online at
  2054. http://www.opengroup.org/unix/online.html .
  2055. .PP
  2056. Any typographical or formatting errors that appear
  2057. in this page are most likely
  2058. to have been introduced during the conversion of the source files to
  2059. man page format. To report such errors, see
  2060. https://www.kernel.org/doc/man-pages/reporting_bugs.html .