0

Have lot of questions in ksh as i struggle to understand the code. here is one which i couldnt find the answer

function prn_msg
{
   print "command usage: "
   print "   $COMMAND -i<id> -d<date>"
    exit $BADOPTIONS
} 1>&2

I understood that it prints the text to a stderr output and exits the shell execution with the return code in BADOPTIONS. but don't understand what does the 1>&2 do

xGen
  • 494
  • 3
  • 10
  • 27

1 Answers1

1

In the comment OP asks for a simple answer. The link given by @Bernard tells more, two simple answers are:

Output to the screen is divided in (1) normal output and (2) error output. 1>&2 is a method to reroute normal output to the error output.

and

It is a way to make the output of that function being written to stderr, which can be filtered later.

Note: I never use 1>&2 but use 2>&1 a lot. That way you can redirect both to a file or /dev/null.

Walter A
  • 19,067
  • 2
  • 23
  • 43