Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to I run a command in a shell script auto prompting yes to prompt to the use, so I can automate a script?

share|improve this question
up vote 5 down vote accepted

You can use the yes binary.

share|improve this answer

expect is the usual tool for this.

share|improve this answer
I do this for various scripts run by cron when there isn't another/easier option. The Wikipedia should be able to get you started. – J.Zimmerman Nov 12 '09 at 7:32
In this case, it's what '/usr/bin/yes' was built for – Philip Reynolds Nov 12 '09 at 9:57

You should read the docs for the commands you are using in your script. Most commands that are regularly used in scripts have options that you can use to automatically respond confirmation messages.

share|improve this answer

If by "commands" you mean the built in cmd/dos functions like COPY XCOPY, MKDIR, etc), then you want to add the /y parameter to each command. It defaults to Yes for the built in command-line functions.

But as Zoredache mentions, you should read the documention of each command you are doing (that is non-built-in functions) and find out how to default to Yes (if possible).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.