在 bash 脚本中模拟 ENTER 按键 [英] Simulating ENTER keypress in bash script

查看:72
本文介绍了在 bash 脚本中模拟 ENTER 按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的 bash 脚本来运行一些命令.这些命令之一在运行时需要用户输入.即它询问用户你想要等等等等吗?",我想简单地向它发送一个输入按键,以便脚本完全自动化.

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.

推荐答案

echo -ne '
' | <yourfinecommandhere>

或者利用 echo 生成的隐式换行符(感谢 Marcin)

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

echo | <yourfinecommandhere>

现在我们可以简单地使用 --sk 选项:

Now we can simply use the --sk option:

--sk, --skip-keypress 不要在每次测试后等待按键

--sk, --skip-keypress Don't wait for a keypress after each test

sudo rkhunter --sk --checkall

这篇关于在 bash 脚本中模拟 ENTER 按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆