home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 23.3 Tricks for Making rm Safer Chapter 23
Removing Files
Next: 23.5 Remove Some, Leave Some
 

23.4 Answer "Yes" or "No" Forever with yes

Some commands - like rm -i , find -ok , and so on - ask users to answer a "do it or not?" question from the keyboard. For example, you might use a file-deleting program named del that asks before deleting each file:

% 

del *


Remove file1? 

y


Remove file2? 

y


   ...

If you answer y , then the file will be deleted.

What if you want to run a command that's going to ask you 200 questions and you want to answer y to all of them, but you don't want to type all those y 's in from the keyboard? Pipe the output of yes to the command; it will answer y for you:

% 

yes | del *


Remove file1?
Remove file2?
   ...

If you want to answer n to all the questions, you can do:

% 

yes n | del *

NOTE: Not all UNIX commands read their standard input for answers to prompts. If a command opens your terminal ( /dev/tty ( 45.20 ) ) directly to read your answer, yes won't work. Try expect ( 9.26 ) instead.

yes
yes knows how to say more than just y or n . Article 42.7 shows how to test a terminal with yes .

The CD-ROM has GNU's yes .

- JP


Previous: 23.3 Tricks for Making rm Safer UNIX Power Tools Next: 23.5 Remove Some, Leave Some
23.3 Tricks for Making rm Safer Book Index 23.5 Remove Some, Leave Some

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System