Input from within shell script

前端 未结 4 1059
[愿得一人]
[愿得一人] 2020-12-01 18:44

I have a script that calls an application that requires user input, e.g. run app that requires user to type in \'Y\' or \'N\'.
How can I get the shell script not to ask

4条回答
  •  情书的邮戳
    2020-12-01 19:26

    You can pipe in whatever text you'd like on stdin and it will be just the same as having the user type it themselves. For example to simulating typing "Y" just use:

    echo "Y" | myapp
    

    or using a shell variable:

    echo $ANSWER | myapp
    

    There is also a unix command called "yes" that outputs a continuous stream of "y" for apps that ask lots of questions that you just want to answer in the affirmative.

提交回复
热议问题