IEEE Standards Interpretations for IEEE Std 1003.2™-1992 IEEE Standard for Information Technology--Portable Operating System Interfaces (POSIX®)--Part 2: Shell and Utilities
Copyright © 1996 by the Institute of Electrical and Electronics Engineers, Inc. 3 Park Avenue New York, New York 10016-5997 USA All Rights Reserved.
Interpretations are issued to explain and clarify the intent of a standard and do not constitute an alteration to the original standard. In addition, interpretations are not intended to supply consulting information. Permission is hereby granted to download and print one copy of this document. Individuals seeking permission to reproduce and/or distribute this document in its entirety or portions of this document must contact the IEEE Standards Department for the appropriate license. Use of the information contained in this document is at your own risk.
IEEE Standards Department, Copyrights and Permissions, 445 Hoes Lane, Piscataway, New Jersey 08855-1331, USA
Interpretation Request #81
Topic: sed Relevant Clauses: 4.55
POSIX.2 Subclause 4.55 specifies the semantics of the "sed" utility. In subclause 22.214.171.124 the semantics of various subcommands are specified. My question has to do with the "a" and "r" subcommands. The description of the "a" subcommand states that the command [1addr]a\ shall cause sed to Write to standard output just before each attempt to fetch a line of input, whether by executing the N command or by beginning a new cycle. Similarly, the description of the "r" subcommand states that the command [1addr]r shall cause sed to Copy the contents of to standard output just before each attempt to fetch a line of input. My question has to do with the behavior of these commands on the first input line when the address is omitted.
In such a case, POSIX.2 states (subclause 126.96.36.199) that A command with no addresses shall select every pattern space. If sed is executed with a script that includes an "a" command or an "r" command with no addresses, is the action of "a" or "r" taken prior to input of the first line in the input stream? My reading of the above sections of the standard is that this action should be taken prior to fetching each line, including the first one. However, it appears that existing practice is for the action of "a" or "r" to occur on each fetch attempt after the first, but not on the first. Does this behavior conform to the requirements of POSIX.2?
The standard states the behavior for input and addressing for sed, and conforming implementations must conform to this. However, concerns have been raised about this which are being referred to the sponsor.
Rationale for Interpretation