views:

69

answers:

2

Is it possible to have a bash script automatically complete prompts that would normally be presented to the user with default actions? Currently I am using a bash script to call an in-house tool that will display prompts to the user (prompting for Y/N) to complete actions, however the script I'm writing needs to be completely "hands-off", so I need a way to send Y|N to the prompt to allow the program to continue execution. Is this possible?

+6  A: 

This is not "auto-completion", this is automation. One common tool for these things is called Expect.

You might also get away with just piping input from yes.

unwind
Unfortunately I can't use expect as their are stringent space requirements on the system running this so I can't add extra packages, but piping `yes` in did the trick, luckily all the prompts only required a 'y' anyway. Thanks.
tj111
+4  A: 

A simple

echo "Y Y N N Y N Y Y N" | ./your_script

This allow you to pass any sequence of "Y" or "N" to your script.

Loïc Février
If I needed to send any `N`'s, I would have used this method, but I only needed Y's so I went with `yes`. Too bad I can't accept two answers, since they are both correct.
tj111
;) Well if you ever need to send some `N` you now have a good way to do it.
Loïc Février