相关疑难解决方法(0)

阅读前清除标准输入

我有以下 bash 脚本:

# do some time consuming task here
read -p "Give me some input: " input
Run Code Online (Sandbox Code Playgroud)

现在您可能已经猜到了,如果用户在“耗时任务”期间按了一些随机键,那么不需要的输入也会被考虑在内。stdin在发出读取命令之前如何清除(或至少忽略它)?

linux bash shell stdin

15
推荐指数
5
解决办法
2万
查看次数

标签 统计

bash ×1

linux ×1

shell ×1

stdin ×1