# $OpenBSD: POSIX,v 1.2 1996/06/26 05:39:04 deraadt Exp $ # from: @(#)POSIX 8.1 (Berkeley) 6/6/93 Comments on the IEEE P1003.2 Draft 12 Part 2: Shell and Utilities Section 4.55: sed - Stream editor Diomidis Spinellis Keith Bostic In the following paragraphs, "wrong" usually means "inconsistent with historic practice", as most of the following comments refer to undocumented inconsistencies between the historical versions of sed and the POSIX 1003.2 standard. All the comments are notes taken while implementing a POSIX-compatible version of sed, and should not be interpreted as official opinions or criticism towards the POSIX committee. All uses of "POSIX" refer to section 4.55, Draft 12 of POSIX 1003.2. 1. 32V and BSD derived implementations of sed strip the text arguments of the a, c and i commands of their initial blanks, i.e. #!/bin/sed -f a\ foo\ \ indent\ bar produces: foo indent bar POSIX does not specify this behavior as the System V versions of sed do not do this stripping. The argument against stripping is that it is difficult to write sed scripts that have leading blanks if they are stripped. The argument for stripping is that it is difficult to write readable sed scripts unless indentation is allowed and ignored, and leading whitespace is obtainable by entering a backslash in front of it. This implementation follows the BSD historic practice. 2. Historical versions of sed required that the w flag be the last flag to an s command as it takes an additional argument. This is obvious, but not specified in POSIX. 3. Historical versions of sed required that whitespace follow a w flag to an s command. This is not specified in POSIX. This implementation permits whitespace but does not require it. 4. Historical versions of sed permitted any number of whitespace characters to follow the w command. This is not specified in POSIX. This implementation permits whitespace but does not require it. 5. The rule for the l command differs from historic practice. Table 2-15 includes the various ANSI C escape sequences, including \\ for backslash. Some historical versions of sed displayed two digit octal numbers, too, not three as specified by POSIX. POSIX is a cleanup, and is followed by this implementation. 6. The POSIX specification for ! does not specify that for a single command the command must not contain an address specification whereas the command list can contain address specifications. The specification for ! implies that "3!/hello/p" works, and it never has, historically. Note, 3!{ /hello/p } does work. 7. POSIX does not specify what happens with consecutive ! commands (e.g. /foo/!!!p). Historic implementations allow any number of !'s without changing the behaviour. (It seems logical that each one might reverse the behaviour.) This implementation follows historic practice. 8. Historic versions of sed permitted commands to be separated by semi-colons, e.g. 'sed -ne '1p;2p;3q' printed the first three lines of a file. This is not specified by POSIX. Note, the ; command separator is not allowed for the commands a, c, i, w, r, :, b, t, # and at the end of a w flag in the s command. This implementation follows historic practice and implements the ; separator. 9. Historic versions of sed terminated the script if EOF was reached during the execution of the 'n' command, i.e.: sed -e ' n i\ hello '