Xargs 命令在 Linux 上有效,但在 Mac 上无效

Xargs 命令在 Linux 上有效,但在 Mac 上无效

我在我的 mac 上运行了以下 xargs 命令

echo replace | xargs -n 1 -I {} echo "asdf asdf adf asdf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf adf asdf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf{} asd"

它给出的输出如下,而不是打印整个字符串

asdf asdf adf asdf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf adf

我在 Linux 机器上尝试过同样的操作,得到了预期的输出。你能告诉我如何在 mac 上实现这个功能吗?

asdf asdf adf asdf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf adf asdf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdf asdf asdf asdf adf asdfreplace asd

答案1

xargs(1)手册页

 -I replstr
         Execute utility for each input line, replacing one or more
         occurrences of replstr in up to replacements (or 5 if no -R
         flag is specified) arguments to utility with the entire
         line of input.  The resulting arguments, after replacement
         is done, will not be allowed to grow beyond 255 bytes;

然后如果我们计算你的命令生成的字符

$ wc -c out
     255 out

所以你遇到了记录的限制。解决方法是不这样做(到底需要什么这么长的争论?)或者安装一些 Linux 版本xargs并调用它。

相关内容