View Issue Details

IDProjectCategoryView StatusLast Update
00009621003.1(2013)/Issue7+TC1Shell and Utilitiespublic2019-06-10 08:54
Reporterrhymoid Assigned To 
PrioritynormalSeverityCommentTypeClarification Requested
Status ClosedResolutionAccepted As Marked 
NameStijn van Drongelen
Organization
User Reference
Sectionsort
Page Number3211
Line Number107616-107618
Interp StatusApproved
Final Accepted Textsee 0000962:0002764
Summary0000962: Should utilities continue when reading one of multiple files fails?
DescriptionConsider the following sequence of commands:

    set +e

    rm -f aaaa
    echo something >xxxx
    echo c_mpletely >yyyy
    echo different >zzzz

    cat aaaa xxxx 2>/dev/null
    sed -e s/_/o/ aaaa yyyy 2>/dev/null
    sort aaaa zzzz 2>/dev/null

On FreeBSD and Mac OS X, this sequence prints the following to standard output

    something
    completely

To be specific: cat and sed continue their task when a specified file could not be opened, while sort terminates without output to stdout when any of the specified files could not be opened.

From the description of cat in the POSIX specification, it seems that it is not defined whether the cat, sed, and sort utilities should terminate when an error occurred when processing a specified file. It would seem that the output of the sequence above may range from "" to "something\ncompletely\ndifferent\n" across POSIX implementations.
Desired ActionClarify the constraints, if any, on the behaviour of cat, sed, and sort when opening or reading one of their input files fails.
Tagstc2-2008

Activities

geoffclare

2015-06-22 08:41

manager   bugnote:0002727

See XCU 1.4 Utility Description Defaults, under CONSEQUENCES OF ERRORS, where it says:

    The following shall apply to each utility, unless otherwise stated:

    * If the requested action cannot be performed on an operand
      representing a file, directory, user, process, and so on, the
      utility shall issue a diagnostic message to standard error and
      continue processing the next operand in sequence, but the final
      exit status shall be returned as non-zero.


It appears that most, if not all, implementations of sort do not follow this general rule. We should add something to the sort page (either in OPERANDS or CONSEQUENCES OF ERRORS) to say that if sort encounters an error when opening or reading a file operand, it may exit without processing later operands.

rhansen

2015-07-16 16:15

manager   bugnote:0002764

Interpretation response
------------------------
The standard states that sort must carry on processing later operands after an error is encountered with an earlier operand, and conforming implementations must conform to this. However, concerns have been raised about this which are being referred to the sponsor.

Rationale:
-------------
Existing implementations of sort stop processing immediately after encountering an error when reading input files.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------
On page 3211 line 107618 (sort OPERANDS), append the following to the description of the file operand:
If sort encounters an error when opening or reading a file operand, it may exit without writing any output to standard output or processing later operands.

On page 3213 line 107687 (sort CONSEQUENCES OF ERRORS), change from:
Default.
to:
The default requirements shall apply, except that if sort encounters an error when opening or reading a file operand, it may exit without writing any output to standard output or processing later operands.

ajosey

2015-07-17 07:59

manager   bugnote:0002769

Interpretation Proposed: 17 July 2015

ajosey

2015-09-07 11:32

manager   bugnote:0002816

Interpretation approved: 7 Sep 2015

Issue History

Date Modified Username Field Change
2015-06-20 20:42 rhymoid New Issue
2015-06-20 20:42 rhymoid Name => Stijn van Drongelen
2015-06-20 20:42 rhymoid Section => cat, sed, sort
2015-06-20 20:42 rhymoid Page Number => N/A
2015-06-20 20:42 rhymoid Line Number => N/A
2015-06-22 08:41 geoffclare Note Added: 0002727
2015-07-16 15:53 rhansen Section cat, sed, sort => sort
2015-07-16 15:53 rhansen Page Number N/A => 3211
2015-07-16 15:53 rhansen Line Number N/A => 107616-107618
2015-07-16 15:53 rhansen Interp Status => ---
2015-07-16 16:15 rhansen Note Added: 0002764
2015-07-16 16:16 rhansen Interp Status --- => Pending
2015-07-16 16:16 rhansen Final Accepted Text => see 0000962:0002764
2015-07-16 16:16 rhansen Status New => Interpretation Required
2015-07-16 16:16 rhansen Resolution Open => Accepted As Marked
2015-07-16 16:16 rhansen Tag Attached: tc2-2008
2015-07-17 07:59 ajosey Interp Status Pending => Proposed
2015-07-17 07:59 ajosey Note Added: 0002769
2015-09-07 11:32 ajosey Interp Status Proposed => Approved
2015-09-07 11:32 ajosey Note Added: 0002816
2019-06-10 08:54 agadmin Status Interpretation Required => Closed