如何将 yes 传递给 xargs 启动的程序?

How can I pipe yes to a program started by xargs?

背景

yes command is a means to automatically hit yes when dealing with multiple prompts that you know you will hit yes to. An example of yes in action is depicted below from How to Geek:

yes | sudo apt-get install fortune-mod

这将自动安装包中的所有内容,并在每次出现提示时点击“是”继续。此示例非常适合描述将 yes 的输出通过管道传输到将显示多个 "y/n" 输出的一个命令的示例。

问题

我有一串命令要串联执行,最后一个会弹出几个"y/n"提示。以下是我的命令的草稿版本:

yes | cat alistOfDirectories.txt | xargs -I{} cleartool rmname {}/bad_file.txt

每次调用 rmname 时,仍然会弹出 "y/n" 提示,然后出现大量其他错误,使整个过程脱轨。

问题

如何通过多个管道将 yes 的输出正确地传输到最后一个命令?

这实际上不是关于 yes 和多个管道的问题,而是关于 xargs 的问题:您的问题是如何将某些内容发送到 xargs 命令的标准输入运行。

答案(感谢)是你可以告诉xargs从标准输入以外的地方获取它的输入,然后向前它运行的命令的标准输入。看起来像这样:

yes | xargs -a alistOfDirectories.txt -I{} cleartool rmname {}/bad_file.txt