How to Automate Scripts Using the yes Command in Linux

When you execute a complex bash script that attempts to install 50 different software packages via the command line, the installation process will often violently halt and prompt you with a question (e.g., “Do you want to continue? [y/N]”). If you are not sitting at the keyboard to physically press the “y” key and hit Enter, the script will freeze indefinitely. To mathematically force the Linux kernel to automatically, infinitely answer “yes” to every single prompt an installer throws at it, you must use the yes command.

How the yes Command Works

The yes command is an incredibly simple, highly aggressive text generation engine. If you execute the command by itself in an empty terminal, it will instantly begin printing the letter “y” (followed by a line break) to your screen millions of times per second. It will never stop until you violently terminate the process by pressing Ctrl + C.

yes

Output:

y
y
y
y
...

Automating Bash Scripts

While printing “y” to the screen is useless on its own, it becomes incredibly powerful when combined with a standard Linux pipe (|). A pipe takes the output of one command and forcefully shoves it directly into the input of a second command.

If you have a massive bash script named install_server.sh that is going to ask you “Are you sure?” 15 different times, you can pipe the yes command directly into the script’s execution path:

yes | ./install_server.sh

The moment you press Enter, the yes engine spins up. It stands by in the background. The exact millisecond the install_server.sh script halts and prompts for user input, the yes engine violently shoves a “y” and a Return keystroke directly into the prompt. The script instantly accepts the input and continues processing. The engine will automatically answer every single prompt instantly, allowing you to walk away from the server while it configures itself autonomously.

Generating Custom Text Strings

While the command is literally named “yes” and defaults to the letter “y”, you can mathematically force it to print absolutely any text string you desire. This is highly useful if a poorly coded legacy script specifically requires you to type the word “Accept” instead of “y”.

Simply type the command followed by your exact text string:

yes Accept | ./legacy_installer.sh

The engine abandons the letter “y” completely and instantly begins firing the word “Accept” into the pipeline infinitely, perfectly bypassing the strict requirements of the automated script.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.