Simulating ENTER pressing in bash script

I created a really simple bash script that runs several commands. one of these commands requires user input at runtime. that is, it asks the user β€œdo you want blah blah blah?", I want to just send an introductory click on this so that the script is fully automated.

I do not need to wait for input or anything at runtime, just send it a keystroke and the input buffer will process the rest.

+79
linux bash shell ubuntu
Jun 07 2018-11-11T00:
source share
5 answers
echo -ne '\n' | <yourfinecommandhere> 

or use an implicit line feed that generates an echo (thanks to Marsin)

 echo | <yourfinecommandhere> 

Now we can just use --sk :

--sk , --skip-keypress Do not wait for keystrokes after each test

those. sudo rkhunter --sk --checkall

+115
Jun 07 2018-11-11T00:
source share
β€” -

You can find the helpful yes command.

See man yes

+36
Jun 07 2018-11-11T00:
source share

You can just use yes .

 # yes "" | someCommand 
+24
Aug 31 '16 at 19:18
source share

The following is an example of using expect :

 #!/usr/bin/expect set timeout 360 spawn my_command # Replace with your command. expect "Do you want to continue?" { send "\r" } 

Check out: man expect for more information.

+21
Apr 11 '16 at 8:30
source share

You can use expect (man expect comes with examples).

+11
Jun 07 2018-11-11T00:
source share



All Articles