如何在 fish shell 中打印到 stderr?

How to print to stderr in fish shell?

在 fish-shell 脚本中,如何将错误消息打印到 stderr?

例如,此消息应该转到 stderr 流而不是默认的 stdout 流。

echo "Error: $argv[1] is not a valid option"

您可以将输出重定向到 stderr,例如:

echo "Error: $argv[1] is not a valid option" 1>&2

作为参考,这里有一些适用于 fish* 的常见 IO 重定向。

foo 1>&2 # Redirects stdout to stderr, same as bash

bar 2>&1 # Redirects stderr to stdout, same as bash

bar ^&1  # Redirects stderr to stdout, the fish way using a caret ^

* stdin、stdout 和 stderr 的文件描述符是 0、1 和 2。
* & 表示您想重定向到文件流而不是文件。
* Comparison of redirection in various shells(bash、鱼、ksh、tcsh、zsh)