如何将键盘输入传递给linux命令? [英] how to pass keyboard input along to linux command?

查看:167
本文介绍了如何将键盘输入传递给linux命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行linux命令,有时会要求用户输入(按1或2).

I run a linux command that sometimes asks for user input (press 1 or 2).

我一直想回答1,如何自动传递该值?

I always want to answer 1, how can I pass this value automatically ?

推荐答案

使用管道|运算符将一个命令的输出连接到另一个命令的输入.

Use the pipe | operator to connect the output of one command to the input of another.

echo 1 | command

如果要重复输入命令,可以使用yes.默认情况下,它会重复发送字符串"y",但还会重复发送您选择的其他字符串.

If you want to repeat some input to a command, you can use yes. By default it sends the string "y" repeatedly but it also repeat a different string of your choice.

yes | cp * /tmp  # Answer "y" to all of cp's "Are you sure?" prompts.
yes 1 | command  # Answer "1" repeatedly until the command exits.

这篇关于如何将键盘输入传递给linux命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆