File descriptor before a command

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error File descriptor before a command on this date .

What does this mean? to have the file descriptor before a command line utility.

Example,

>&2 echo "Hey there! Something failed"

Afaik, it should have been at the end of a command line utility or a program.

echo "Hey there! Something failed" 1>&2

Which at least gives a fair readability to the reader that even the stdout is copied to stderr

I came across such a line of code in one of the Open source git-hub project. Not able to understand the usage

Answer

The position of the redirection operators doesn’t matter – some people like putting them at the beginning of a command, some people like the end. The shell itself doesn’t care.

From the bash manual:

The following redirection operators may precede or appear anywhere within a simple command or may follow a command.