如何通过管道将xargs启动的程序为yes? [英] How can I pipe yes to a program started by xargs?

查看:45
本文介绍了如何通过管道将xargs启动的程序为yes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令是自动执行的一种方法当您处理多个知道的提示时,请单击是".下面的

The 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"输出.

This will automatically install everything in the package and hit yes to continue at each prompt. This example is excellent for describing an example of piping the output of yes to one command that will present several "y/n" outputs.

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

I have a string of commands I want to execute in tandem, and the last one will bring up several "y/n" prompts. Below is the draft version of my command:

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

每次 rmname 被调用,仍然弹出"y/n"提示,然后出现了许多其他错误,使整个过程脱轨.

Each time rmname is invoked, a "y/n" prompt still pops up and then a whole host of other errors appear that derail the entire process.

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

How do I properly pipe the output of yes to the last command through several pipes?

推荐答案

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

This isn't really a question about yes and multiple pipes, but about xargs: your question is how to send something to the standard input of the command that xargs runs.

答案(感谢 https://stackoverflow.com/a/19963123/978917 )是您可以告诉 xargs 从标准输入之外的其他地方获取 输入,然后将其标准输入转发给它运行的命令.看起来像这样:

The answer (thanks to https://stackoverflow.com/a/19963123/978917) is that you can tell xargs to take its input from somewhere other than standard input, and just forward its standard input to the command it runs. That looks like this:

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

这篇关于如何通过管道将xargs启动的程序为yes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆