首页 > 解决方案 > 为什么管道会截断内容,而重定向到/从中间文件不会?

问题描述

当按以下顺序使用管道时,我看到我的内容被截断:

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不用作上述管道序列的下游部分的输入,仅在稍后的一些命令中使用。

使用--unbufferedinjq没有帮助。

这种行为差异的原因是什么,我该如何解决?


MacOS High Sierra 10.13.6 (17G5019) GNU bash,版本 3.2.57(1)-release (x86_64-apple-darwin17)

标签: bashmacos

解决方案


推荐阅读