如何回复linux提示(基于提示中的关键字)

如何回复linux提示(基于提示中的关键字),linux,shell,command-line-interface,prompt,Linux,Shell,Command Line Interface,Prompt,我想在提示中用关键字empty present回答yes,在not中回答other 我试过了,但没用 rm -i test_file* rm: remove regular empty file 'test_file'? rm: remove regular file 'test_file1'? 键入时: yes | grep "empty" | rm -i test_file* 您正在将yes result传递给grep,而grep不知道应该将yes result传递给rm 您可以在bas

我想在提示中用关键字empty present回答yes,在not中回答other

我试过了,但没用

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

yes | grep "empty" | rm -i test_file*
您正在将yes result传递给grep,而grep不知道应该将yes result传递给rm

您可以在bash的单个文件上这样做:

yes | grep "empty" | rm -i test_file*
在多个文件上仍然使用bash:

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

您正在使用bash的哪个shell?从命令输出中搜索不是有效的方法,您可以使用find吗?如果您的目的是删除所有零字节文件?@Inian是对的,请查找-name test_file*-type f-empty-delete trickIt是否包含两个删除单个文件的调用!!那么,OP中基于查找的解决方案在那时仍然有效;是的,但我正在寻找回复提示逻辑:在这种情况下,您应该关注返回值而不是文本,而且我的第二个代码段也可以做到这一点。&&是一个逻辑and运算符。
for file in *.dat; do file $file | grep empty && yes | rm -v $file ; done