How to trap

I have a script

#!/bin/ksh

trap cleanup 20

cleanup()
{
  cat $t.log
  echo Caught
  exit 1
}

if [ `echo ABCDEFGHORA|grep -is "ORA"` ];then
  echo Found >>t.log
  exit 20
else
  echo Not found >>t.log
  exit 20
fi

Please tell me how to trap the signal.

What is the problem exactly? Your script already traps signal 20.

However, exit code 20 is something entirely different than signal 20. Trapping pseudo-signal 0 allows you to perform an action when the script terminates (regardless of the exit code).

Its not calling the function and not printing the "Caught" statement.

If you are expecting "exit 20" to generate the signal, it doesn't work that way. A signal (an interrupt) is something generated by an external event; this is what you can "catch" with the trap keyword. You can generate the signal by hand with kill -s 20 (processid) to trigger the trap. I'm guessing that is not the problem you want to solve in the first place, though, based on your script and your question.

Again, coincidentally, you can set up a trap to handle "signal" 0 (there is no such signal, per se, it's just a special case of trap), however. It will not care what number you use after exit but execute whenever the script exits.

#!/bin/sh

trap ketchup 0

ketchup () {
  cat t.log
  echo caught
  exit $?
}

if echo ABCDEFGHORA|grep -is "ORA" >/dev/null; then
  echo Found
else
  echo Not found
fi >>t.log

No explicit exit is required, either; the event will trigger when the script simply ends.

I made some stylistic changes to the conditional logic as well.

Thanks for the information. So in shell scripts we do not have anything by which we can throw and catch user defined error?

You can do a conditional inside the trap or something, but the concept of catch / throw is not directly supported, no.