bash - read -t 没有在 bash 中暂停我的 while 循环
问题描述
我试图在 bash 中创建一个简单的循环,一个一个地列出目录中的所有文件。
我想Enter
在进行下一个之前必须先打。我认为添加read
会使循环暂停。但它并没有暂停。它一次列出所有文件。这是我正在使用的命令
find . -type f | while read -r line; do echo "$line"; read -t 1; done`
解决方案
你可以这样做:
# redirect fd=3 from 0
exec 3<&0
while IFS= read -rd '' line; do
echo "$line"
# read from fd=3 and wait for 1 sec
read -u 3 -t 1
done < <(find . -type f -print0)
# close fd=3
exec 3<&-
推荐阅读
- php - 更改 phpspreadsheet 中的保存目录
- vb.net - 数据网格视图链接
- r - 使用 merge() 在 R 中修复.by() 错误
- assembly - MOV AL, 0FH 是什么意思
- php - 更好的解决方案作为我的 ajax 帖子?
- javascript - 获取 jsfiddle json 内容
- c# - 将 Int32 添加到列表
尽管成功,但使用 AddRange 抛出异常 - node.js - 在 Express.js 服务器中,如何发送从 HTTP 请求获取的 HTML(带有样式和 js)作为响应?
- angular - 从 Angular 到 React - 如何将业务逻辑与组件解耦?
- c++ - 整数作为 8 传递给函数,但函数内部的值为 -439854520