bash中的"1& 2"是什么意思?

问题描述:

bash脚本中的"1>& 2"是什么意思?

What does "1>&2" mean in a bash script?

例如,bash脚本的以下行是做什么的?

For instance, what does the following line from a bash script do?

echo "$1 is not a directory!" 1>&2

我使用Mac OSX.我的bash脚本是:

I use mac os x. My bash script is:

if [ ! -d $1 ]; then
    echo "$1 is not a directory" 1>&2
    exit 1
fi

它将消息输出到stderr."1>& 2"表示将标准输出重定向到标准错误. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

It outputs the message to stderr. "1>&2" means redirect stdout to stderr. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html