2017-09-14 25 views
0

我想自動執行一系列命令,其中一個命令需要多個用戶輸入yes/no。我如何編寫腳本以便我的腳本自動選擇多個答案?從命令checkinstall響應多個y/n腳本提示; shellscript

例子:

Do you want me to list them? [n]:(我要回答沒有/ N這裏)

Should I exclude them from the package? [n]:(我想回答是/ Y在這裏)

正如你可以看到checkinstall命令需要1個以上的輸入。當我想給一個命令1輸入時,我使用this方法。

回答

2

在這裏使用文檔<<

checkinstall <<EOF 
no 
yes 
EOF 
0

你可以腳本預計

#!/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 
0

嘗試yes

yes $'n\ny' | checkinstall 

如果您不止一次地調用您的命令,也可以工作。

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