Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

bash - echo输出到stderr(echo that outputs to stderr)

Is there a standard Bash tool that acts like echo but outputs to stderr rather than stdout?

(是否有一个标准的Bash工具,它像echo一样输出到stderr而不是stdout?)

I know I can do echo foo 1>&2 but it's kinda ugly and, I suspect, error prone (eg more likely to get edited wrong when things change).

(我知道我可以做echo foo 1>&2但它有点难看,我怀疑,容易出错(例如,当事情发生变化时更有可能被编辑错误)。)

  ask by BCS translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could do this, which facilitates reading:

(你可以这样做,这有助于阅读:)

>&2 echo "error"

>&2 copies file descriptor #2 to file descriptor #1.

(>&2文件描述符# >&2复制到文件描述符#1。)

Therefore, after this redirection is performed, both file descriptors will refer to the same file: the one file descriptor #2 was originally referring to.

(因此,在执行此重定向之后,两个文件描述符将引用相同的文件:一个文件描述符#2 最初是指。)

For more information see the Bash Hackers Illustrated Redirection Tutorial .

(有关更多信息,请参阅Bash Hackers Illustrated Redirection Tutorial 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...