在不那么没用" YES接bash命令:如何在每一个循环确认命令 [英] The not-so-useless "yes" bash command: how to confirm a command in every loop

查看:174
本文介绍了在不那么没用" YES接bash命令:如何在每一个循环确认命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个循环来解压目录中的所有zip文件。

I wrote a loop to unzip all zip files in a directory.

for f in *zip
do
    unzip $f
done

不过,我必须确认每一步的覆盖:

However, I have to confirm the overwrite at every step:

replace file123.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A

我怎么可以重写一个循环,在每次循环发送相同的命令?

How can I rewrite a loop to send at every cycle the same command?

推荐答案

精彩,不多的情况下也许有其中仍然是有用的。

Wonderful, maybe one of the few cases where yes is still useful

试着用:

for f in *zip
do
    yes | unzip $f
done

这将打印工作Y在每个命令。

Which will work printing "y" at every command.

或者,您可以指定是提供的字符串,如:

Or alternatively, you can specify the string provided by yes, like:

for f in *zip
do
    yes A | unzip $f
done

这篇关于在不那么没用" YES接bash命令:如何在每一个循环确认命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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