简体   繁体   English

如何通过Linux命令传递多个键盘输入

[英]How to pass multiple keyboard inputs along with linux command

I run a linux command that sometimes asks for user input (press y or n). 我运行linux命令,有时会要求用户输入(按y或n)。

After that for the same command I need to pass (yes/no) 之后,对于同一命令,我需要通过(是/否)

I always want to answer y,and after that yes, how can I pass this value automatically ? 我一直想回答y,然后是,我如何自动传递该值?

For 1 argument I knew that we can use echo y|command 对于1个参数,我知道我们可以使用echo y | command

But,for multiple inputs I do not know how???? 但是,对于多个输入,我不知道如何?

After Passing y, I should also able to give yes Is there a way??? 通过y之后,我还应该给出yes。有没有办法???

Use yes Utility 使用yes工具

You can use the yes command if you always want to pass the same value. 如果您始终希望传递相同的值,则可以使用yes命令。 For example: 例如:

yes | ./script.sh

Use Expect, Variables, or Configuration Files 使用Expect,变量或配置文件

If you need anything more complex, then yes usually can't do what you want directly. 如果您需要更复杂的东西,那么是的通常无法直接做您想做的事情。 Instead, you should use expect to script complex interactions, or rewrite your shell scripts to use variables or configuration files to pass parameters. 相反,您应该使用Expect编写复杂交互的脚本,或者重写Shell脚本以使用变量或配置文件来传递参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM