Sunday, December 6, 2009

Answering Yes to Prompts Automatically

The yes command can be used to pipe a series of y's to another command, so that the user does not have to wait to be prompted during the command's execution.

For example, after a Linux install, I went to use CPAN for the first time to install the File::Find::Rule module.

  prystasj@prystasj:~$ cpan -i "File::Find::Rule"

CPAN is the world-wide archive of perl resources.
...
Would you like me to configure as much as possible automatically? [yes]
While answering yes above will configure CPAN automaticaly, I'll still be prompted to answer questions regarding the module's dependencies:
  Writing Makefile for File::Find::Rule
Falling back to other methods to determine prerequisites
---- Unsatisfied dependencies detected during ----
---- RCLAMP/File-Find-Rule-0.32.tar.gz ----
Number::Compare [requires]
Text::Glob [requires]
Shall I follow them and prepend them to the queue of modules
we are processing right now? [yes]
To automatically answer yes to every question, you can pipe the output of the yes command to the prompting command. For example:
  prystasj@prystasj:~$ yes | cpan -i "File::Find::Rule"
Now I can install the module without watching the command's progress.

No comments:

Post a Comment