How can I respond to prompts in a Linux Bash script automatically?

Ron picture Ron · Nov 24, 2016 · Viewed 22.4k times · Source

I am running a script (I can't edit it), and there are three yes/no questions. How can I automatically respond to these questions? I need to answer yes, yes, no (in that order).

Answer

Cyrus picture Cyrus · Nov 24, 2016

Try this:

echo -e "yes\nyes\nno" | /path/to/your/script

From help echo:

-e: enable interpretation of the following backslash escapes