Have bash script answer interactive prompts [duplicate]

Is it possible to have a bash script automatically handle 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?


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.


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.


If you only have Y to send :

$> yes Y |./your_script

If you only have N to send :

$> yes N |./your_script

I found the best way to send input is to use cat and a text file to pass along whatever input you need.

cat "input.txt" | ./Script.sh