]> git.ipfire.org Git - thirdparty/man-pages.git/commit
src/bin/grepc: Handle xargs(1) errors properly
authorAlejandro Colomar <alx@kernel.org>
Thu, 30 Oct 2025 23:58:42 +0000 (00:58 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sun, 2 Nov 2025 17:52:55 +0000 (18:52 +0100)
commit1af5434f39e81aa71470ed2af595afaa624fe510
tree7ed9246af35be2ec211c461e69645227de0ad7a0
parentef01a3e3ef0f486c6872cd03fa92d00d8a931b7e
src/bin/grepc: Handle xargs(1) errors properly

'xargs grep' is hard, because grep(1) exits with a status of 1 for no
match, which is not an error, but xargs(1) takes that as an error, which
is confused with other errors.

This trick with sh(1) was suggested by Paul, and nicely solves this
problem.

We also need to change $opts to be a normal variable.

We can't export bash array variables, and passing them to sh(1) -c is
not great; escapes could be messed.  It's more robust to use a normal
variable.

Link: <https://lists.gnu.org/archive/html/bug-grep/2025-10/msg00029.html>
Suggested-by: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/bin/grepc