Re: [PATCH 3/6] doc: xargs does not use the (128+sig) convention of /bin/sh.

Bernhard Voelker <[email protected]> Tue, 7 Jul 2026 09:15:16 +0200
Newsgroups gmane.comp.gnu.findutils.bugs,gmane.comp.gnu.findutils.patches
Message-ID <[email protected]>
Hi James,

On 7/6/26 22:06, James Youngman wrote:
> * doc/find.texi: Point out that xargs does not launch commands via the
> shell and does not use the "128 + signal" convention used for $? in
> the shell.
> * xargs/xargs.1: Likewise.
> ---
>   doc/find.texi | 5 +++--
>   xargs/xargs.1 | 8 ++++++--
>   2 files changed, 9 insertions(+), 4 deletions(-)
>=20
> diff --git a/doc/find.texi b/doc/find.texi
> index f693db8c..71b80f53 100644
> --- a/doc/find.texi
> +++ b/doc/find.texi
> @@ -3996,9 +3996,10 @@ if the command is not found
>   if some other error occurred.
>   @end table
>  =20
> -Exit codes greater than 128 are used by the shell to indicate that
> -a program died due to a fatal signal.
>  =20
> +The commands run by @code{xargs} are not invoked via the shell.  The
> +shell's @math{128 + n} convention for reporting that a process had
> +been killed by a signal is not used by @code{xargs}.

While this is correct and, well, describes what xargs does _not_ do,
I think the confusion of the recent bug report stems from the following ro=
w
of the table with the exit codes:

   125    if any invocation of the command exited with status 1-125
_______________________________________________________________^^^

This is not the complete range:

   for f in $(seq 120 130); do echo $f | xargs -I'{}' sh -c 'set -x; exit =
"{}"' sh; echo $?; done
   + exit 120
   123
   + exit 121
   123
   + exit 122
   123
   + exit 123
   123
   + exit 124
   123
   + exit 125
   123
   + exit 126
   123
   + exit 127
   123
   + exit 128
   123
   + exit 129
   123
   + exit 130
   123

The practical range for exit is 0-255.
And xargs(1) itself exits with 123 for all command exit values in 1..254.
Only 0 and 255 are treated different.

   # For all command exit codes, find the ones which make xargs(1) not exi=
t with 123.
   # Finally demonstrate that 256 overflows to 0 (in the shell process, no=
t in xargs).
   for f in $(seq 0 256); do \
     echo $f | xargs -I'{}' sh -c 'exit "{}"' sh; \
     ret=3D$?; \
     test $ret !=3D 123 \
       && echo "$f -> $ret"; \
   done
   0 -> 0
   xargs: sh: exited with status 255; aborting
   255 -> 124
   256 -> 0

Therefore, the documentation fix would be:

-  125    if any invocation of the command exited with status 1-125
+  125    if any invocation of the command exited with status 1-254

WDYT?

Have a nice day,
Berny