Answers:
./feeding_script.sh |
tee >(while read a; do [ "$a" == "12345" ] && </dev/null another_command; done)
笔记:
tee拆分数据流; 一个副本转到“文件”,在这种情况下是一个命令>(…),另一个继续到终端;</dev/null another_command- 此重定向可防止another_command消耗由此生成的数据feeding_script.sh。another_command可以从stdin(没有重定向)自给自足,那么它将能够消耗触发后的任意数量的行12345。这些线永远不会去while read …。我以为他们都应该去那里接受测试。但是,如果这个想法是检测12345作为先于数据的标题应该去到another_command,则</dev/null是错误的。
</dev/null需要它,它将与tee共享相同的stdin?看起来像while和test会首先获得输入,但我不太确定过程替换会发生什么(或者如果another_command需要很长时间并且feeding_script数据备份会发生什么)