bashshellubuntu

Simulating ENTER keypress in bash script


I've created a really simple bash script that runs a few commands. one of these commands needs user input during runtime. i.e it asks the user "do you want to blah blah blah?", I want to simply send an enter keypress to this so that the script will be completely automated.

I won't have to wait for the input or anything during runtime, its enough to just send the keypress and the input buffer will handle the rest.


Solution

  • echo -ne '\n' | <yourfinecommandhere>
    

    or taking advantage of the implicit newline that echo generates (thanks Marcin)

    echo | <yourfinecommandhere>