Simulate key press in bash

后端 未结 2 701
梦如初夏
梦如初夏 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条回答
  •  孤城傲影
    2021-01-06 15:04

    I believe using yes might be enough if your test.sh script doesn't use its standard input for other purposes : yes will produce an infinite stream of lines of y by default, or any other string you pass it as a parameter. Each time the test.sh checks for user input, it should consume a line of that input and carry on with its actions.

    Using yes Y, you could provide your test.sh script with more Y than it will ever need :

    yes Y | test.sh
    

    To use it with your loop, you might as well pipe it to the loop's stdin rather than to the test.sh invocation :

    yes Y | for (( i=0; i <= 5; i++ )) ; do 
     test.sh 
    done
    

提交回复
热议问题