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.
hence typing "\r" for "Enter" key action.
To check for Bash on your computer, you can type “bash” into your open terminal, like shown below, and hit the enter key. Note that you will only get a message back if the command is not successful. If the command is successful, you will simply see a new line prompt waiting for more input.
Here detach takes the place of ctrl + a + d . Sending quit or running exit could often replace ctrl + d . Another work-around would be to use expect which you could then use to send the strings containing control characters or hex values of them.
Printing Newline in Bash The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “\n” is the conventional way. However, it's also possible to denote newlines using the “$” sign.
echo -ne '\n' | <yourfinecommandhere>
or taking advantage of the implicit newline that echo generates (thanks Marcin)
echo | <yourfinecommandhere>
Now we can simply use the --sk
option:
--sk
,--skip-keypress
Don't wait for a keypress after each test
i.e. sudo rkhunter --sk --checkall
You might find the yes
command useful.
See man yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With