linux - 如何回复linux提示(根据提示中的关键字)

标签 linux shell command-line-interface prompt

rm -i test_file*
rm: remove regular empty file 'test_file'?
rm: remove regular file 'test_file1'?

我想在提示中出现的关键字empty中回答“yes”,在not中回答其他。

我试过了(没用)

yes | grep "empty" | rm -i test_file*

最佳答案

当你打字时:

yes | grep "empty" | rm -i test_file*

您正在将 yes 结果传递给 grep,它不知道它应该将 yes 结果传递给 rm

您可以(在 bash 上)对单个文件执行此操作:

file test_file |grep empty && yes | rm -i test_file

在多个文件上(仍然是 bash):

for file in *.dat; do file $file | grep empty && yes | rm -v $file ; done

关于linux - 如何回复linux提示(根据提示中的关键字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45710595/

相关文章:

mysql - 如何在 mysql CLI 中指定终端宽度

c# - 从 C# 应用程序中使用命令行程序

linux - 使用 dup2 替换手动管道的无法解释的行为

linux - fcitx 不适用于 emacsclient --create-frame

mySQL Shell 连接故障排除

bash - shell脚本,for循环,does循环等待执行命令进行迭代

linux - 'sudo find/var/www/html -type d -exec chmod g+s {}\;' 中的 {} 和\是什么意思

php - argparse 像 PHP 的 lib?

python - 在Linux Mint系统上运行的应用程序未收到udp数据包

c - 为什么程序没有执行这个C编程或unix编程中的一些语句(execvp()系统调用)?