Ravichandra
Ravichandra

Reputation: 2332

How to reply linux prompt (based on keywords in prompt)

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

I want to reply "yes" in key word empty present in prompt and reply other in not.

I tried (it's not working)

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

Upvotes: 0

Views: 84

Answers (1)

peyo
peyo

Reputation: 451

When you are typing:

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

You are passing yes result to grep which has no idea it should pass yes result to rm

YOu can do it this way (on bash) on a single file:

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

On multiple files (still bash):

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

Upvotes: 1

Related Questions