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 #105
Topic: expr standard output representing a null string Relevant Clauses: 220.127.116.11
In IEEE Std 1003.2-1992 subclause 18.104.22.168 (Standard Output of the expr utility), P276, L4127-4129, the description of the standard output representing expressions evaluating to zero and to null strings is: The character '0' shall be written to indicate a zero value and nothing shall be written to indicate a null string. This could be interpreted literally to mean that the output in these two cases must not include a newline character. (At least one developer of a POSIX.2 test suite has used this interpretation for the null string, but not for '0'.) In both BSD and System V historic practice, an expression evaluating to zero produced "0\n" on standard output and an expression evaluating to a null string produced an empty line on standard output. The rationale in clause E.4.22, P904, L6209-6213 acknowledges that expr could be replaced by other shell constructs in the POSIX.2 shell, but says the utility was kept because of the many historical shell scripts that use it. The rationale also mentions that other changes in early drafts of the standard were backed out because they weren't historic practice (see L6229- 6230). It seems strange that this change to historical practice was not documented if it was intentional. To match historic BSD and System V implementations, the second sentence of the Standard Output section on P276, L4128-2129 should have been something like: An empty line shall be written to indicate a null string. Note that the zero case is already handled in the first sentence in that section. Was this change to historic practice intentional?
The standard is clear that a nl is not appended to the results of the evaluation in any case. This is not historical behavior, however, conforming implementations must conform to this. However, concerns have been raised about this which are being referred to the sponsor.
Rationale for Interpretation