Automatically press Enter to continue in Bash

Simons0n picture Simons0n · Jun 25, 2012 · Viewed 16.3k times · Source

I want to change RSA Keys to open ssh connections without any problems. It works fine, if I use this tutorial but I want to have it done in a bash script. Unfortunately I am asked to enter a passphrase (I want to enter nothing). How can I achieve to automatically press Enter three times in a row, when the script reaches this point?

This thread did not help, because I am not allowed to install new programs on my work PC and the echo | command trick seems only to work for one Enter. Also I need to enter "n" and Enter, if the procedure was already made, to not overwrite any files. How do i achieve that?

Answer

smocking picture smocking · Jun 25, 2012

If you just need to press Enter a bunch of times this will do it:

yes "" | command

For anything more complicated than that you might want to use expect as suggested in the other thread, which you can install in your homedir without root priviliges.

PS: Please avoid re-posting questions in the future. If you don't like an answer for some reason, just comment on it.