Have bash script answer interactive prompts

TJ L picture TJ L · Sep 27, 2010 · Viewed 155.8k times · Source

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?

Answer

Loïc Février picture Loïc Février · Sep 27, 2010

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.