回应多个y / n脚本提示;的shell

时间:2017-09-14 10:14:47

标签: bash shell sh

我想自动化一系列命令,其中一个命令需要多个用户输入是/否。如何编写脚本以便我的脚本自动选择多个答案?

命令checkinstall的示例:

Do you want me to list them? [n]: (我想在这里回答否/ n)

Should I exclude them from the package? [n]: (我想在这里回答是/否)

如您所见,checkinstall命令需要多于1个输入。当我想给命令1输入时,我使用this方法。

3 个答案:

答案 0 :(得分:2)

此处使用文档<<

checkinstall <<EOF
no
yes
EOF

答案 1 :(得分:0)

您可以使用expect编写脚本

#!/usr/bin/expect

set timeout 20

spawn "./application"

expect "Are you a human?: " { send "yes\r" }
expect "Are you a android :" { send "no\r" }

interact

答案 2 :(得分:0)

尝试yes

yes $'n\ny' | checkinstall

如果您不止一次致电您的命令,也可以使用。

yes $'n\ny' | for n in 1 2 3; do checkinstall; done