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 #140
Topic: awk - reevaluation of field varibles Relevant Sections: 4.1.2
In Section 4.1.2 it says: The symbol $0 shall refer to the entire record; setting any other field shall cause the reevaluation of $0. and Assigning $0 shall reset the value of all other fields and the NF built-in variable. The questions are: 1) how exactly is $0 to be re-evaluated? Should it be using the current value of OFS? Note: This is how its historically been documented on page 36 in The AWK Programming Language (1988) by Aho, Kernighan and Weinberger. Also, section 184.108.40.206 (line 314-317) implies this behaviour since this is what is done when an assignment is made to a non-existent field. 2) (a)When $0 is assigned to, how exactly should the other fields bbe reset? (b)What does "reset" mean exactly?
Note: Historical documentation (The AWK Programming Language) ssays that "when $0 is changed by assignment or substitution, $1, $2, etc., and the NF will be recomputed" (c) Is there a reason why POSIX.2 is not more specific on how these fields should be reset? (d) Is it reasonable to assume that the fields shall be computed from the new $0 using FS? (e)If so, then should this FS be the current value (at time $0 was assignment) or should it be the value that was current when the last record was read? (See somewhat related 1003.2 interp. request #118 and #80)
Q.1: The standard states on page 163, section 4.1.2 (last paragraph), that $0 is re-evaluated if any field is set. Page 171, section 220.127.116.11 third paragraph, indicates that assignments to non-existent fields cause the value of $0 to be recomputed with the fields seperated by the value of OFS Since "recomputed" and "re-evaluated" are neither one clearly defined, then the standard is unclear in what it means for $0 to be re-evaluated, and no conformance distinction can be made between alternative implementations based on this. However, it is clear that the current value of OFS should be used whenever $0 is re-computed. When $0 is re-evaluated it is unclear if OFS or FS is used.
Q.2: (a)The standard is unclear on this issue, it states that they are "reset" but does not define what reset means. (b)The standard does not specify what "reset" means. (c)The interpretations committee believes that the authors of the standard did not realise these ambiguities were present in the specification. (d)Yes, although the standard is unclear on this issue, we believe using the value of FS while resetting the values of fields when $0 is reassigned is consistent with the standard. (e)The standard does not speak to this issue, and as such no conformance distinction can be made between alternative implementations based on this. These issues are being forwarded to the sponsor.
Rationale for Interpretation