Interpretations

Answering questions that may arise related to the meaning of portions of an IEEE standard concerning specific applications.

IEEE Standards Interpretation for IEEE Std 1003.1™-2001 IEEE Standard Standard for Information Technology -- Portable Operating System Interface (POSIX®)

Copyright © 2006 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 #92
Topic: sort, Utility Syntax Guideline 13 Relevant Sections: XCU sort, XBD 12.2

Does the command "sort -o -" create a file named "-", or doesit write to standard output?

The specification for "sort" says that it conforms to the Utility Syntax Guidelines, and Guideline 13 says

For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used only to mean standard input (or standard output when it is clear from context that an output file is being specified).

Here, "-" is an operand, so apparently "sort -o -" should write to standard output. This is what GNU coreutils 5.2.1 "sort" does.

However, I just checked Solaris 9 "sort" (both /usr/bin/sort and /usr/xpg4/bin/sort) and OpenBSD 3.4 "sort", and they both create an output file "-". It sounds like the standard is not clear enough here, perhaps because of the indirect reference to the Guidelines.

Append the following text after page 871 line 33829:

If "output" is "-", sort shall write to standard output.

Interpretation Response
The standard clearly states the requirements for sort,and conforming implementations must conform to this.

The standard is unclear in Guideline 13 of XBD 12.2, and no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor.

Rationale for Interpretation
In the example given
sort -o -
the final "-" is an option argument; not an operand. The description of the -o option says that the output option argument is the name of an output file to be used instead of standard output, so a file named "-" shall be created. No change is necessary to the standard.