-I option in xargs sometimes stops working

Asked 1 years ago, Updated 1 years ago, 108 views

I would like xargs to handle the long file path I got from find, but the -I option does not work

directory structure:
Long Path Directory Structure

Commands Executed

 path="What's wrong with you? What's wrong with you? What's wrong with you? What's wrong with you? What's wrong with you? What's wrong with you? What's wrong with you? What's wrong with you? What's wrong with you?
echo "path:${path}"
find"${path}"-mindepth1-maxdepth1-print0 | xargs-0-n1-P10 echo
find "${path}"-mindepth1-maxdepth1-print0 | xargs-0-n1-P10-I{}bash-c "echo{}"

Run Results

$bash./test.sh
path: aye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye
Aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye.DS_Store
Aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye, aye.
{}
{}

As mentioned above, the replacement does not work, and for some reason {} is displayed as it is.
Why is that?

The running environment is masOS Sierra 10.12.6.
Thank you for your cooperation.

bash

2022-09-30 17:16

1 Answers

For macOS xargs, the maximum string after replacement with the -I option appears to be 255 bytes.
According to man xargs:

I replstr
             Execute utility for each input line, replacing one or more occurrences of replacement in up to replacements (or 5 if no-R flag is specified) arguments to utility with the entry line of input.The
             resulting arguments, after replacement is done, will not be allowed to grow Beyond 255 bytes; this implemented by concatenating as much of the argument containing replaceable, to the
             constructed arguments to utility, up to 255 bytes. The 255 byte limit does not apply to arguments to utility which do not contain replstr, and further, no replacement will be done on utility
             itsself.Implies-x.


2022-09-30 17:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.