stderr/stdout

Can somebody explain to me why the diff output is not going to stderr?
Yet when I issue a diff from the command line the return code is -ne 1.
I am guessing diff always writes to stdout???

Is there away I can force the difff to write to stderr USING THE CURRENT
template. If possible, I would like to uncomment the first diff and get
that to write to stderr. Any examples would be greatly appreciated.
This needs to work with ksh.....

Thanks in advance to all who answer

cat /tmp/t1.ksh
============
 
#!/usr/bin/ksh
CheckForError()
{
   ERR_NUM=$1
   touch alert_${ERR_NUM}.now  alert_${ERR_NUM}.prv
   grep ${ERR_NUM} /tmp/alert.log > /tmp/alert_${ERR_NUM}.now
   ##diff /tmp/alert_${ERR_NUM}.prv /tmp/alert_${ERR_NUM}.now | grep '>'| cut -c3-
   diff /tmp/alert_${ERR_NUM}.prv /tmp/alert_${ERR_NUM}.now
}
main()
{
    for error_num in ORA-04030 ORA-04088
    do
      CheckForError $error_num
    done
} >$OUTPUT_FILE 2>$ERR_FILE
OUTPUT_FILE=/tmp/junk1.out
ERR_FILE=/tmp/junk1.err
main
return 0

 
cat /tmp/alert.log
==============
 
ORA-04030: out of process memory when trying to allocate 8528 bytes
ORA-04030: out of process memory when trying to allocate 2072 bytes
ORA-04030: out of process memory when trying to allocate 1280 bytes
ORA-04088: error during execution of trigger 'XXX.INS_TRIG'
 

You need to use the ampersand notation. Like this:

$ ( echo hello ) 2> errfile
hello
$ cat errfile
$
$ ( echo hello >&2 ) 2> errfile
$ cat errfile
hello
$
$

Try this:

diff /tmp/alert_${ERR_NUM}.prv /tmp/alert_${ERR_NUM}.now 1>&2

Thanks guys, I always use 2>&1 it never occured to me to change the
order.

ineresting solution, can you explain it as now I am curious.

I looks like in the parenthesise you redirecting the word "hello" to
stderr but what does this do 2>errfile or why is it needed?

Thanks

parentheses create a subshell and I sent the subshell's stderr to errfile. Then in the subshell I show an echo command both without and then with the needed redirection.