bash 中的“1>&2”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38757862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does “1>&2” mean in bash?
提问by beginner
What does "1>&2" mean in a bash script?
"1>&2" 在 bash 脚本中是什么意思?
For instance, what does the following line from a bash script do?
例如,bash 脚本中的以下行有什么作用?
echo " is not a directory!" 1>&2
I use mac os x. My bash script is:
我使用 mac os x。我的 bash 脚本是:
if [ ! -d ]; then
echo " is not a directory" 1>&2
exit 1
fi
回答by Robert Columbia
It outputs the message to stderr. "1>&2" means redirect stdout to stderr. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
它将消息输出到 stderr。“1>&2”表示将标准输出重定向到标准错误。http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html