xref: /freebsd/bin/ed/POSIX (revision 05248206f720394d95c2a7475429311df670a2e9)
189730b29SDavid Greenman
295e6217eSAndrew MooreThis version of ed(1) is not strictly POSIX compliant, as described in
395e6217eSAndrew Moorethe POSIX 1003.2 document.  The following is a summary of the omissions,
495e6217eSAndrew Mooreextensions and possible deviations from POSIX 1003.2.
530154ac8SAndrew Moore
695e6217eSAndrew MooreOMISSIONS
795e6217eSAndrew Moore---------
8ed9b87e3SSheldon Hearn1) For backwards compatibility, the POSIX rule that says a range of
995e6217eSAndrew Moore   addresses cannot be used where only a single address is expected has
1095e6217eSAndrew Moore   been relaxed.
1130154ac8SAndrew Moore
12ed9b87e3SSheldon Hearn2) To support the BSD `s' command (see extension [1] below),
1395e6217eSAndrew Moore   substitution patterns cannot be delimited by numbers or the characters
1495e6217eSAndrew Moore   `r', `g' and `p'.  In contrast, POSIX specifies any character expect
1595e6217eSAndrew Moore   space or newline can used as a delimiter.
1630154ac8SAndrew Moore
1795e6217eSAndrew MooreEXTENSIONS
1895e6217eSAndrew Moore----------
1995e6217eSAndrew Moore1) BSD commands have been implemented wherever they do not conflict with
2095e6217eSAndrew Moore   the POSIX standard.  The BSD-ism's included are:
2195e6217eSAndrew Moore	i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution,
2295e6217eSAndrew Moore	ii) `W' for appending text to an existing file,
2395e6217eSAndrew Moore	iii) `wq' for exiting after a write,
2495e6217eSAndrew Moore	iv) `z' for scrolling through the buffer, and
2595e6217eSAndrew Moore	v) BSD line addressing syntax (i.e., `^' and `%')  is recognized.
2630154ac8SAndrew Moore
27*d83db3fbSConrad Meyer2) The POSIX interactive global commands `G' and `V' are extended to
2895e6217eSAndrew Moore   support multiple commands, including `a', `i' and `c'.  The command
2995e6217eSAndrew Moore   format is the same as for the global commands `g' and `v', i.e., one
3095e6217eSAndrew Moore   command per line with each line, except for the last, ending in a
3195e6217eSAndrew Moore   backslash (\).
3230154ac8SAndrew Moore
33*d83db3fbSConrad Meyer3) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is
3495e6217eSAndrew Moore   that <file> arguments are processed for backslash escapes, i.e.,  any
3595e6217eSAndrew Moore   character preceded by a backslash is interpreted literally.  If the
3695e6217eSAndrew Moore   first unescaped character of a <file> argument is a bang (!), then the
3795e6217eSAndrew Moore   rest of the line is interpreted as a shell command, and no escape
3895e6217eSAndrew Moore   processing is performed by ed.
3930154ac8SAndrew Moore
40*d83db3fbSConrad Meyer4) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked
4195e6217eSAndrew Moore   as red.  This limits editing of files in the local directory only and
4295e6217eSAndrew Moore   prohibits shell commands.
4310ca1c6cSAndrew Moore
4495e6217eSAndrew MooreDEVIATIONS
4595e6217eSAndrew Moore----------
4695e6217eSAndrew Moore1) Though ed is not a stream editor, it can be used to edit binary files.
4795e6217eSAndrew Moore   To assist in binary editing, when a file containing at least one ASCII
4895e6217eSAndrew Moore   NUL character is written, a newline is not appended if it did not
4995e6217eSAndrew Moore   already contain one upon reading.  In particular, reading /dev/null
5095e6217eSAndrew Moore   prior to writing prevents appending a newline to a binary file.
5110ca1c6cSAndrew Moore
5295e6217eSAndrew Moore   For example, to create a file with ed containing a single NUL character:
5395e6217eSAndrew Moore      $ ed file
5495e6217eSAndrew Moore      a
5595e6217eSAndrew Moore      ^@
5695e6217eSAndrew Moore      .
5795e6217eSAndrew Moore      r /dev/null
5895e6217eSAndrew Moore      wq
5995e6217eSAndrew Moore
6095e6217eSAndrew Moore    Similarly, to remove a newline from the end of binary `file':
6195e6217eSAndrew Moore      $ ed file
6295e6217eSAndrew Moore      r /dev/null
6395e6217eSAndrew Moore      wq
6495e6217eSAndrew Moore
6595e6217eSAndrew Moore2) Since the behavior of `u' (undo) within a `g' (global) command list is
6695e6217eSAndrew Moore   not specified by POSIX, it follows the behavior of the SunOS ed:
6795e6217eSAndrew Moore   undo forces a global command list to be executed only once, rather than
68bf2fe08eSUlrich Spörlein   for each line matching a global pattern.  In addition, each instance of
6995e6217eSAndrew Moore   `u' within a global command undoes all previous commands (including
7095e6217eSAndrew Moore   undo's) in the command list.  This seems the best way, since the
7195e6217eSAndrew Moore   alternatives are either too complicated to implement or too confusing
7295e6217eSAndrew Moore   to use.
7395e6217eSAndrew Moore
7495e6217eSAndrew Moore   The global/undo combination is useful for masking errors that
7595e6217eSAndrew Moore   would otherwise cause a script to fail.  For instance, an ed script
76bf2fe08eSUlrich Spörlein   to remove any occurrences of either `censor1' or `censor2' might be
7795e6217eSAndrew Moore   written as:
7895e6217eSAndrew Moore   	ed - file <<EOF
7995e6217eSAndrew Moore	1g/.*/u\
8095e6217eSAndrew Moore	,s/censor1//g\
8195e6217eSAndrew Moore	,s/censor2//g
8295e6217eSAndrew Moore	...
8395e6217eSAndrew Moore
8495e6217eSAndrew Moore3) The `m' (move) command within a `g' command list also follows the SunOS
8510ca1c6cSAndrew Moore   ed implementation: any moved lines are removed from the global command's
8610ca1c6cSAndrew Moore   `active' list.
8795e6217eSAndrew Moore
8895e6217eSAndrew Moore4) If ed is invoked with a name argument prefixed by a bang (!), then the
8995e6217eSAndrew Moore   remainder of the argument is interpreted as a shell command.  To invoke
9095e6217eSAndrew Moore   ed on a file whose name starts with bang, prefix the name with a
9195e6217eSAndrew Moore   backslash.
92