What Does “1>&2” Mean in Bash? [Duplicate]

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

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

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

I use MacOS X. My bash script is:

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

It outputs the message to stderr. Therefore 1>&2 means redirect stdout to stderr.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest