bash - 为什么管道会截断内容,而重定向到/从中间文件不会?
问题描述
当按以下顺序使用管道时,我看到我的内容被截断:
jq ... |
jq ... |
tee tee_file |
jq ... |
# content gets truncated here
head ... | sed ... | awk ... | awk ... | sed
...但是如果我将输出重定向到中间文件,一切正常,然后立即将该文件提供给下游进程:
jq ... |
jq ... |
tee some_file |
jq ... > intermediary_file
# content remains intact here
cat intermediary_file |
head ... | sed ... | awk ... | awk ... | sed
tee_file
不用作上述管道序列的下游部分的输入,仅在稍后的一些命令中使用。
使用--unbuffered
injq
没有帮助。
这种行为差异的原因是什么,我该如何解决?
MacOS High Sierra 10.13.6 (17G5019) GNU bash,版本 3.2.57(1)-release (x86_64-apple-darwin17)
解决方案
推荐阅读
- shopify - 如何在没有管理员身份的情况下通过特定语言的 REST API 检索 Shopify 产品?
- xml - 其相应 XML 文件的 XSD 等效项
- typescript - 我如何告诉 TypeScript 我的 isFinite 比 typeof any === 'number' 还要好?
- php - Preg_replace 内容与 mysql 查询
- ubuntu-18.04 - 为 ubuntu 18.04 安装 tmux:包具有未满足的依赖项
- html - css字体系列代码不适用于自定义文本
- nlp - 如何从 word2vec 的语料库中找到相似的句子?
- flutter - List.generate 在 null 上调用了 getter 'length'。接收方:null 尝试调用:长度
- flutter - 如何在颤动中创建 AppBar 的自定义形状?
- mysql - 数据库和模式之间有什么区别?