The following issue has been SUBMITTED. 
====================================================================== 
https://austingroupbugs.net/view.php?id=1853 
====================================================================== 
Reported By:                geoffclare
Assigned To:                
====================================================================== 
Project:                    1003.1(2024)/Issue8
Issue ID:                   1853
Category:                   Shell and Utilities
Type:                       Clarification Requested
Severity:                   Objection
Priority:                   normal
Status:                     New
Name:                       Geoff Clare 
Organization:               The Open Group 
User Reference:              
Section:                    xargs 
Page Number:                3602 
Line Number:                123241 
Interp Status:              --- 
Final Accepted Text:         
====================================================================== 
Date Submitted:             2024-09-02 14:27 UTC
Last Modified:              2024-09-02 14:27 UTC
====================================================================== 
Summary:                    xargs -x lost an important detail between Issue 6
and 7
Description: 
In Issue 6 the description of xargs -x was:<blockquote>Terminate if a
command line containing <i>number</i> arguments (see the -n option above)
[XSI] or <i>number</i> lines (see the -L option above) [/XSI] will not fit
in the implied or specified size (see the -s option above).</blockquote>
In Issue 7 it became:<blockquote>Terminate if a constructed command line
will not fit in the implied or specified size (see the -s option
above).</blockquote>
An important feature of the Issue 6 text was that if you specify, say, -n 2
in order to process input arguments in pairs, and there is a pair of
arguments for which the constructed command will not fit, then without -x
xargs would execute a command with only one argument, whereas with -x it
will terminate. The new text allows xargs to execute a command with only
one argument regardless of whether -x is specified.

I have tracked down the source of the change to XCU ERN 68 in
https://www.opengroup.org/austin/aardvark/latest/xcubug2.txt

The relevant part of the problem statement is:<pre> 2.  (objection) The
synopsis shows that the -x option can only be
     used with the -n option, but the options section indicates that
     it can be used both with -n and -L and is forced on with -I.  It
     also indicates that -x interacts with the size specified by a
     -s option or by the default command line size if the -s option
     is not specified.

     In fact, with sufficiently long arguments on the xargs command
     line, the -x option is needed even when -I, -L, -n, and -s are
     not specified.  Existing practice seems to be that -x is not
     tied to any of these options and should be available no matter
     what other options are specified.</pre>
Clearly there was no intention to alter the behaviour when -x is used with
-n. The desire was to clarify its use without -n. Unfortunately, the
side-effect on -n of simplifying the text was not noticed.

Also, the final sentence quoted above is not true for some systems: macOS
and FreeBSD (and presumably other BSDs) only accept -x with -n.

Although -x is accepted on many systems independently of other options, it
is not clear what effect it is supposed to have if none of -n, -L, or -I is
specified. The current description "Terminate if a constructed command line
will not fit in the implied or specified size (see the -s option above)"
just appears to state something that xargs should do regardless of whether
-x is specified. I.e. if a command that uses only the next argument from
the input won't fit, then xargs should report an error.

On Solaris -x is a no-op if neither -n nor -L is not specified.

It's possible that the original source of the confusion is the statement
for -I that "Option -x shall be forced on."  This was always meaningless
and unnecessary, and trying to read meaning into it could have led to
misinterpreting what the purpose of -x is. The purpose of -x is illustrated
in example 2 in the standard (which shows how to use xargs to invoke diff
with successive pairs of arguments).

My proposed wording changes only require that systems accept -x when either
-n or -L is also used (so that macOS and the BSDs don't need to accept -x
with other options in order to conform). This means applications can no
longer portably specify -x and -I together, but since -x is required to be
a no-op when used with -I it seems highly unlikely that any application
does this. In any case, the combination will undoubtedly continue to be
accepted on implementations that already accept it.

Finally, the new text for -x misuses the word "constructed". The first
paragraph of the DESCRIPTION says that xargs "shall construct a command
line consisting of the utility and argument operands specified followed by
as many arguments read in sequence from standard input as fit in length and
number constraints specified by the options". Thus constructed command
lines always fit. Instead of "if a constructed command line will not fit",
the -x text should say "if a command line that will fit cannot be
constructed".

Desired Action: 
On page 3600 line 123148 section xargs (SYNOPSIS), change:
<blockquote><pre>xargs [-prtx] [-E <i>eofstr</i>|-0] [<XSI>-I
<i>replstr</i>|-L <i>number</i></XSI>|-n <i>number</i>]
</pre></blockquote>
to:
<blockquote><pre>xargs [-prt] [-E <i>eofstr</i>|-0] [<XSI>-I
<i>replstr</i>|-L <i>number</i> [-x]|</XSI>-n <i>number</i> [-x]]
</pre></blockquote>
After page 3600 line 123162 section xargs (DESCRIPTION), add a
paragraph:<blockquote>Each constructed command line shall include at least
one argument from standard input. It shall be an error if a command line
that will fit in the implied or specified size (see the <b>-s</b> option)
cannot be constructed containing even one argument.</blockquote>
On page 3601 line 123206 section xargs (OPTIONS, -I),
delete:<blockquote>Option <b>-x</b> shall be forced on.</blockquote>
On page 3602 line 123241 section xargs (OPTIONS, -x),
change:<blockquote>Terminate if a constructed command line will not fit in
the implied or specified size (see the <b>-s</b> option
above).</blockquote>
to:<blockquote>Terminate if a command line containing <i>number</i>
arguments (see the <b>-n</b> option) <XSI>or <i>number</i> lines (see the
<b>-L</b> option)</XSI> that will fit in the implied or specified size (see
the <b>-s</b> option) cannot be constructed. Applications should use the
<b>-x</b> option when it would not be appropriate for constructed commands
to contain fewer than <i>number</i> arguments; for example, when executing
the <i>diff</i> utility with <b>-n</b> 2 in order to compare pairs of
files.</blockquote>
After page 3605 line 123412 section xargs (RATIONALE), add a
paragraph:<blockquote>Editions of this standard between 2008 and 2024 did
not require <i>xargs</i> to terminate if <b>-x</b> and <b>-n</b>
<i>number</i> were both specified and a command line containing
<i>number</i> arguments could not be constructed. This requirement was
unintentionally lost while simplifying the description of <b>-x</b>. These
editions continued to show (in EXAMPLES) the use of <b>-x</b> to force all
executions of <i>diff</i> to be passed two operands. The requirement has
now been reinstated. In addition, prior to 2008 it was unclear whether
conforming XSI implementations were required to accept <b>-x</b> with
<b>-L</b> <i>number</i> (because although this combination was described in
the text, the SYNOPSIS did not require it to be accepted). Editions between
2008 and 2024 required the combination to be accepted, but with the same
defect as for <b>-x</b> <b>-n</b> <i>number</i>. The requirements for
<b>-L</b> now match those for <b>-n</b>. Some implementations accept
<b>-x</i> with other options besides <b>-n</b> and <b>-L</b>, but there is
no reason for portable applications to use such combinations and this
standard does not require them to be accepted.</blockquote>

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2024-09-02 14:27 geoffclare     New Issue                                    
2024-09-02 14:27 geoffclare     Name                      => Geoff Clare     
2024-09-02 14:27 geoffclare     Organization              => The Open Group  
2024-09-02 14:27 geoffclare     Section                   => xargs           
2024-09-02 14:27 geoffclare     Page Number               => 3602            
2024-09-02 14:27 geoffclare     Line Number               => 123241          
2024-09-02 14:27 geoffclare     Interp Status             => ---             
======================================================================


  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group
    • [1003.1... Austin Group Bug Tracker via austin-group-l at The Open Group

Reply via email to