Home > Mobile >  Why xargs doesn't see delimiters on MacOS?
Why xargs doesn't see delimiters on MacOS?

Time:10-22

I'm doing this:

$ echo -e "a\nb" | tr "\n" "\0" | xargs -0 -t echo X

I'm getting:

echo X a b
X a b

I'm expecting:

echo X a
X a
echo X b
X b

What am I doing wrong? It's MacOS.

CodePudding user response:

xargs normally passes groups of arguments to the specified command. As the man page says (with emphasis added):

Any arguments specified on the command line are given to utility upon each invocation, followed by some number of the arguments read from the standard input of xargs.

xargs has several options to limit how many arguments are passed at a time. -n, which just sets a numeric limit, is all you need here:

$ echo -e "a\nb" | tr "\n" "\0" | xargs -0 -n1 -t echo X
echo X a
X a
echo X b
X b
  • Related