【发布时间】:2014-04-14 21:03:14
【问题描述】:
我正在执行:
Command1 | tee >(grep sth) || Command2
我希望 Command2 根据 grep 的退出状态执行,而在当前配置中它是根据 tee。
据我所知 pipefail 和 pipestatus 在这里不起作用(如果我错了,请纠正我)。
根据 Alexej Answer 修改 Origian 问题
我也尝试了Command1 | tee >(grep sth || Command2),它适用于我原来的问题,但是当我试图在子shell中设置我的测试状态时;例如,Command 1 | tee>(grep sth || Result="PASSED") 及以后可以访问我代码的其他块中的 Result。所以我还是有问题。
谢谢
【问题讨论】:
-
command1 | tee | grep sth不起作用吗?有什么理由需要使用 subshell? -
我需要记录“Command1”的输出以及“grep”的输出(一些设备测试要求)。通过使用管道,我无法记录“Command1”的输出。另一种方法是执行 Command1,记录输出,然后第二次执行它并将其通过管道传输到 grep,这很难看 :)。 "command1 | tee | grep sth" 将标准输出重定向到 grep。这是我的第一个问题stackoverflow.com/questions/23066559/… 导致我使用 subshell 和 ....
-
好的,你是说
if (command1 | tee | grep sth &> /dev/null); then command2; fi对吧?
标签: tee subshell exitstatus