反响,输出到标准错误 [英] echo that outputs to stderr
本文介绍了反响,输出到标准错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一个标准的Bash工具,它就像回声,但输出到标准错误而不是标准输出?
Is there a standard Bash tool that acts like echo but outputs to stderr rather than stdout?
我知道我可以做回声美孚1>和2
,但它有点丑陋,我怀疑,容易出错(比如更可能发生事情的变化得到编辑的错误)。
I know I can do echo foo 1>&2
but it's kinda ugly and, I suspect, error prone (e.g. more likely to get edited wrong when things change).
推荐答案
这个问题是老了,但你可以做到这一点,这有利于阅读:
This question is old, but you could do this, which facilitates reading:
>&2 echo "error"
运算符'>和2'的字面意思是文件描述符1(标准输出)的地址重定向到文件描述符2(标准错误),该命令的地址。这取决于你想如何深刻理解它,阅读:<一href=\"http://wiki.bash-hackers.org/howto/redirection_tutorial\">http://wiki.bash-hackers.org/howto/redirection_tutorial
要避免与其他重定向交互使用子shell
To avoid interaction with other redirections use subshell
(>&2 echo "error")
这篇关于反响,输出到标准错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文