xref: /dragonfly/bin/ed/POSIX (revision 6b5c5d0d)
1$FreeBSD: src/bin/ed/POSIX,v 1.7.2.1 2000/07/17 10:42:48 sheldonh Exp $
2$DragonFly: src/bin/ed/POSIX,v 1.2 2003/06/17 04:22:49 dillon Exp $
3
4This version of ed(1) is not strictly POSIX compliant, as described in
5the POSIX 1003.2 document.  The following is a summary of the omissions,
6extensions and possible deviations from POSIX 1003.2.
7
8OMISSIONS
9---------
101) For backwards compatibility, the POSIX rule that says a range of
11   addresses cannot be used where only a single address is expected has
12   been relaxed.
13
142) To support the BSD `s' command (see extension [1] below),
15   substitution patterns cannot be delimited by numbers or the characters
16   `r', `g' and `p'.  In contrast, POSIX specifies any character expect
17   space or newline can used as a delimiter.
18
19EXTENSIONS
20----------
211) BSD commands have been implemented wherever they do not conflict with
22   the POSIX standard.  The BSD-ism's included are:
23	i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution,
24	ii) `W' for appending text to an existing file,
25	iii) `wq' for exiting after a write,
26	iv) `z' for scrolling through the buffer, and
27	v) BSD line addressing syntax (i.e., `^' and `%')  is recognized.
28
292) If crypt(3) is available, files can be read and written using DES
30   encryption.  The `x' command prompts the user to enter a key used for
31   encrypting/ decrypting subsequent reads and writes.  If only a newline
32   is entered as the key, then encryption is disabled.  Otherwise, a key
33   is read in the same manner as a password entry.  The key remains in
34   effect until encryption is disabled.  For more information on the
35   encryption algorithm, see the bdes(1) man page.  Encryption/decryption
36   should be fully compatible with SunOS des(1).
37
383) The POSIX interactive global commands `G' and `V' are extended to
39   support multiple commands, including `a', `i' and `c'.  The command
40   format is the same as for the global commands `g' and `v', i.e., one
41   command per line with each line, except for the last, ending in a
42   backslash (\).
43
444) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is
45   that <file> arguments are processed for backslash escapes, i.e.,  any
46   character preceded by a backslash is interpreted literally.  If the
47   first unescaped character of a <file> argument is a bang (!), then the
48   rest of the line is interpreted as a shell command, and no escape
49   processing is performed by ed.
50
515) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked
52   as red.  This limits editing of files in the local directory only and
53   prohibits shell commands.
54
55DEVIATIONS
56----------
571) Though ed is not a stream editor, it can be used to edit binary files.
58   To assist in binary editing, when a file containing at least one ASCII
59   NUL character is written, a newline is not appended if it did not
60   already contain one upon reading.  In particular, reading /dev/null
61   prior to writing prevents appending a newline to a binary file.
62
63   For example, to create a file with ed containing a single NUL character:
64      $ ed file
65      a
66      ^@
67      .
68      r /dev/null
69      wq
70
71    Similarly, to remove a newline from the end of binary `file':
72      $ ed file
73      r /dev/null
74      wq
75
762) Since the behavior of `u' (undo) within a `g' (global) command list is
77   not specified by POSIX, it follows the behavior of the SunOS ed:
78   undo forces a global command list to be executed only once, rather than
79   for each line matching a global pattern.  In addtion, each instance of
80   `u' within a global command undoes all previous commands (including
81   undo's) in the command list.  This seems the best way, since the
82   alternatives are either too complicated to implement or too confusing
83   to use.
84
85   The global/undo combination is useful for masking errors that
86   would otherwise cause a script to fail.  For instance, an ed script
87   to remove any occurences of either `censor1' or `censor2' might be
88   written as:
89   	ed - file <<EOF
90	1g/.*/u\
91	,s/censor1//g\
92	,s/censor2//g
93	...
94
953) The `m' (move) command within a `g' command list also follows the SunOS
96   ed implementation: any moved lines are removed from the global command's
97   `active' list.
98
994) If ed is invoked with a name argument prefixed by a bang (!), then the
100   remainder of the argument is interpreted as a shell command.  To invoke
101   ed on a file whose name starts with bang, prefix the name with a
102   backslash.
103