如何模拟连续两次回车键presses在bash脚本的命令? [英] How to simulate two consecutive ENTER key presses for a command in a bash script?

查看:214
本文介绍了如何模拟连续两次回车键presses在bash脚本的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


它可以被认为是一个扩展[这个问题] [1]。
回声|命令
上述命令可以用来提供一张ENTER字符命令的第一个输入请求。

It can be considered as an extension to [this question][1]. echo | command The above command can be used to supply one 'ENTER' character to the command's first input request.

我怎么能在它的第二个输入请求提供下一个ENTER字符相同的命令。

How can i supply the next 'ENTER' character to the same command in its second input request.

如果需要任何其他细节请评论。

Please comment if any other details are required.

我给,我要实现的具体例子。
我需要在我的shell脚本来运行 SSH-凯基条命令。
它会要求输入如下:

Am giving the specific example which i want to implement. I need to run SSH-keyGen commmand in my shell script. It will ask for following inputs:


  1. 输入目标文件名

  2. 输入密码短语

  3. 再次输入密码短语

我们如何可以通过这三个输入命令?

How can we pass these three inputs to the command?

我试过,

echo -ne "\n \n"| ssh-keygen  //which is passing two new lines for the first input request only.


回声-ne\\ n|(回声-ne\\ n| SSH-凯基)//但还是没有阳性结果

请注意:上午避免上述两个命令的输入文件名的请求,只是为了让事情变得简单

Note: Am avoiding the input file name request in the above two command, just to make the things simple

推荐答案

例如,您可以使用

echo -e "\n"

echo -en "\n\n"

-e 选项告诉回声国米preT转义字符。 \\ n 是换行(回车)字符。因此,第一个版画由于 \\ n换行,然后从另外一个回声通常追加一个换行符。

The -e option tells echo to interpret escape characters. \n is the newline (enter) character. So the first prints a newline due to \n, and then another one since echo usually appends a newline.

-n 选项告诉回声共进晚餐preSS增加一种隐含的换行符。为了得到两个新行,因此,你需要指定两个 \\ n

The -n option tells echo to suppress adding an implicit newline. To get two newlines, you thus need to specify two \n.

编辑:

这里的问题是, SSH-凯基是特殊的。出于安全考虑,密码不是从标准输入读取,而是直接从终端!为了提供一个密码(即使是空的),你需要使用 -P 选项。既然你那么只需要一个Enter(对于文件路径的提示),这个命令应该工作:

The problem here is that ssh-keygen is special. Due to security considerations, the passphrase is not read from standard input but directly from the terminal! To provide a passphrase (even an empty one) you need to use the -P option. Since you then only need one ENTER (for the file path prompt), this command should work:

echo | ssh-keygen -P ''

(注意两个 与之间没有空格:它们很重要)

(note the two ' with no space in between: they are important!)

这篇关于如何模拟连续两次回车键presses在bash脚本的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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