Finding error code

Hi Guys,
Can you tell me how to find error code generated by a command.
Say i run a command and its generating an error how do i find out its error code ( i know its done using redirection operator.......but not sure how)?

The "$?" variable is equal to the error return of the previous program. You can remember this variable, print it out, or perform different actions based on various errors. You can use this to pass information back to the calling shell by exiting a shell script with the number as an argument. Example:

#!/bin/sh
# this is script1
exit 12

Then the following script

#!/bin/sh
script1
echo $?

would print 12.

Thanks a lot man.
Thanks for your help.