将 stdout 和 stderr 都用管道输送到鱼中 shell
pipe both, stdout and stderr in the fish shell
我知道这个问题已经有一段时间了,我发现了很多关于它的讨论,但是我没有得到最终完成它的方法:管道,stdout 和 stderr。在 bash 中,这很简单:
cmd 2>&1 | cmd2
该语法也适用于 fish。演示:
$ function cmd1
echo "this is stdout"
echo "this is stderr" >&2
end
$ function cmd2
rev
end
$ cmd1 | cmd2
this is stderr
tuodts si siht
$ cmd1 &| cmd2
rredts si siht
tuodts si siht
文档:https://fishshell.com/docs/current/language.html#redirects
还有一个方便的快捷方式,根据这些 docs
&>
这是相关引述(强调和白色 space,我的):
As a convenience, the redirection &>
can be used to direct both stdout
and stderr to the same destination. For example:
echo hello &> all_output.txt
redirects both stdout and stderr to the file
all_output.txt
. This is equivalent to echo hello > all_output.txt 2>&1
.
我知道这个问题已经有一段时间了,我发现了很多关于它的讨论,但是我没有得到最终完成它的方法:管道,stdout 和 stderr。在 bash 中,这很简单:
cmd 2>&1 | cmd2
该语法也适用于 fish。演示:
$ function cmd1
echo "this is stdout"
echo "this is stderr" >&2
end
$ function cmd2
rev
end
$ cmd1 | cmd2
this is stderr
tuodts si siht
$ cmd1 &| cmd2
rredts si siht
tuodts si siht
文档:https://fishshell.com/docs/current/language.html#redirects
还有一个方便的快捷方式,根据这些 docs
&>
这是相关引述(强调和白色 space,我的):
As a convenience, the redirection
&>
can be used to direct both stdout and stderr to the same destination. For example:echo hello &> all_output.txt
redirects both stdout and stderr to the file
all_output.txt
. This is equivalent toecho hello > all_output.txt 2>&1
.