I am contemplating about some nuances of xargs.
Reading the question: ( what is the difference between -L and -n in xargs ) I feel irritated.
When I use a multiple argument command sh -c "..." xargs does wrong (I think):
Either a bug in MacOS and FreeBSD and Linux or something I am missing here:
$ ls *.h | xargs -L 1 sh -c 'echo "$# -- $*"'
3 -- quick brown fox.h
I would have expected the same as
$ ls *.h | xargs -L 1
the quick brown fox.h
But it seems, the "sh -c '...'" eats one argument (`the')
Anyone knows why and how to fix ?
Here's an excerpt of
man sh(under Debian 11):That means that if you execute
sh -c 'echo "blah"' the quick brown fox, the first word after the command string (i.e.the) will be used to set$0(command name), and the remaining words will be assigned to$1,$2and$3.Illustration:
So, either put a trailing command_name argument in your
xargsinvocation:... or use another command than
sh -c.Hope that helps.