Is there any Linux command which supplies multiple enter keys to another process which is running in a terminal till the other process dies?

For example consider the command yes ' ' | ./ssr-sim prepare. I need a command on the LHS side of the pipe(|). For example instead of yes ' ' on the left of |, another command which supplies multiple enter keys to the ./ssr-sim prepare on the right side.

I wanted to automate enter keys inside a shell script and the command ./ssr-sim prepare produces output which asks for password multiple number of times and the user needs to manually press the Enter key every time (no need to give password here, only press Enter each time when it asks for password). I need to automate that pressing of enter key part.
The command yes ' ' | ./ssr-sim prepare is not working.


If echoing or yesing input to an interactive program isn't enough to fool it, this is usually because it tries to be clever and checks whether its input is really a terminal or a pipe. For that, you need a larger hammer; the one that people usually wield is expect, which was written to circumvent this problem.

  • >Thanks for the update. But can you be specific means how to add expect along with this command ./ssr-sim config profilename. – Subi Suresh Mar 21 '14 at 11:30
  • My script is a bash shell script and i am using ./ssr-sim config profilename command inside my shell script and this command expects multiple ENTER KEYS in between.i wanted to automate that part of pressing enter keys whenever it asks to press enter key.and continue with my rest of the line of scripts – Subi Suresh Mar 21 '14 at 11:32
printf \\n%.0b `seq 1 ${NUMBER OF TIMES YOU WANT}` | $CMD

If your $CMD doesn't like the pipe you can try:

printf 'PRESS CTRL+V then ENTER TWICE\n' >&2 ; read -r ENTER

    $(printf "$ENTER\n%.0b" `seq 1 ${NUMBER OF TIMES YOU WANT}`)

If that doesn't work you should look into a solution like the expect already mentioned, or a pty. For instance, zsh has a builtin zpty module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.