我知道这已经有一段时间了,我发现了很多关于它的讨论,但是我没有得到最终的方法来完成它:管道,stdout和stderr.在bash中,这将是简单的:
cmd 2>&1 | cmd2
Run Code Online (Sandbox Code Playgroud)
gle*_*man 33
这种语法也适用于鱼类.演示:
$ function cmd1
sh -c 'echo "this is stdout"; echo "this is stderr" >&2'
end
$ function cmd2
rev
end
$ cmd1 | cmd2
this is stderr
tuodts si siht
$ cmd1 2>&1 | cmd2
rredts si siht
tuodts si siht
Run Code Online (Sandbox Code Playgroud)
您还cmd1 ^&1 | cmd2可以使用fish的stderr重定向符号.
文档:https://fishshell.com/docs/current/index.html#redirects
小智 15
根据这些文档,还有一个方便的快捷方式
&>这是相关的引用(强调和空白,我的):
为了方便起见,可以使用重定向将 stdout和 stderr定向到同一目的地。例如:
&>Run Code Online (Sandbox Code Playgroud)echo hello &> all_output.txt将stdout和stderr重定向到文件
all_output.txt。这相当于echo hello > all_output.txt 2>&1.