Simulate key press in bash

后端 未结 2 721
梦如初夏
梦如初夏 2021-01-06 14:08

I have a question, Im having very simple script that starts anpther binary file in loop it looka like this:

for (( i=0; \\\\$i <= 5; i++ )) ; do 
 test.sh         


        
2条回答
  •  猫巷女王i
    2021-01-06 15:09

    Something like the following code snippet should work :

    for (( i=0; i <= 5; i++ ))
    #heredoc. the '-' is needed to take tabulations into acount (for readability sake)
    #we begin our expect bloc
    do /bin/usr/expect <<-EOD
        #process we monitor
        spawn test.sh
        #when the monitored process displays the string "[Y/n]" ...
        expect "[Y/n]"
        #... we send it the string "y" followed by the enter key ("\r") 
        send "y\r"
    #we exit our expect block
    EOD
    done
    

提交回复
热议问题