0

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

4 Answers 4

5

You can use the yes binary.

3

expect is the usual tool for this.

2
  • 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. en.wikipedia.org/wiki/Expect Nov 12, 2009 at 7:32
  • In this case, it's what '/usr/bin/yes' was built for Nov 12, 2009 at 9:57
1

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.

0

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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .