为什么管道会截断内容,而重定向到中间文件却没有呢?

时间:2019-04-12 18:59:51

标签: bash macos

按如下顺序使用管道时,我的内容被截断了:

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中使用jq无济于事。

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


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

0 个答案:

没有答案