gpt4 book ai didi

bash - 如何将键盘输入传递给 linux 命令?

转载 作者:行者123 更新时间:2023-11-29 08:54:15 25 4
gpt4 key购买 nike

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

一直想回答1,怎么自动传这个值?

最佳答案

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

echo 1 | command

如果你想重复某个命令的一些输入,你可以使用yes。默认情况下,它重复发送字符串“y”,但它也会重复您选择的不同字符串。

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

关于bash - 如何将键盘输入传递给 linux 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3385049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com