首页 > 解决方案 > 如何在鱼壳中连接两个无限流?

问题描述

在 Fish shell 中,我如何对命令进行分组,例如所有命令都应该通过管道传送到相同的下一个命令?

例如,在bash

# With "normal" commands
(cat file1; cat file2) | xargs -I% echo 'this is a line: %'

# Or with commands that might not end, to intertwine the output of both
(tail -f infinite-log1 & tail -f infinite-log2) | xargs -I% echo 'this is a line: %'

起初我以为我可以用catand解决它psub,但这不起作用,因为其中任何一个都不是为无限流制作的。

# This won't work
cat (infinite-stream-1 | psub) (infinite-stream-2 | psub) | xargs -I% echo 'this is a line: %'

标签: shellfish

解决方案


你想要beginandend而不是括号。例如

begin; tail -f infinite-log1 & tail -f infinite-log2; end | xargs -I% echo 'this is a line: %'

请注意,fish 的后台功能是有限的,它目前不能使用后台功能。


推荐阅读