-n
在 SmartOS(我假设是 Solaris)中找到的 xargs 上的选项似乎与我遇到的任何其他版本的 xargs 不同。
拿这个例子:
内置 /usr/bin/xargs(奇怪的行为):
# printf 'one\0two\0three' | xargs -0 -I{} -n 1 echo "- {}"
- {} one
- {} two
- {} three
Run Code Online (Sandbox Code Playgroud)
GNU Findutils /opt/local/bin/xargs(预期行为):
# printf 'one\0two\0three' | /opt/local/bin/xargs -0 -I{} -n 1 echo "- {}"
- one
- two
- three
Run Code Online (Sandbox Code Playgroud)
来自 MacOS、NetBSD 和 CentOS 的 Xargs 的行为都与上一个示例相同。SmartOS xargs 有什么不同?
来自 SmartOS xargs 联机帮助页:
-n number
Invokes utility using as many standard input arguments
as possible, up to number (a positive decimal integer)
arguments maximum. Fewer arguments are used if:
o The command line length accumulated exceeds
the size specified by the -s option (or
{LINE_MAX} if there is no -s option), or
o The last iteration has fewer than number, but
not zero, operands remaining.
Run Code Online (Sandbox Code Playgroud)
从 Gnu Findutils xargs 联机帮助页:
-n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, un?
less the -x option is given, in which case xargs will exit.
Run Code Online (Sandbox Code Playgroud)
我在移植 shell 脚本时发现了这种差异,我很好奇是否有人知道为什么行为不同。