Return Codes

I have a simple script which renames a file.How do i capture the return code of the script if the script fails

You can use $? to capture the exit code.

#! /bin/sh

mv file1 file2
exit $?

Hi ,
I have 2 statements in my script.First statement is failing ,but the secodn statement is executing successfully,So when i echo $? ,it shows as 0..
I cannot make both statements as one statement

Any idea how to capture this scnerio

It would like this

command1
ret=$?
if [ $ret -ne 0 ] ; then
  command2
  ret=$?
fi;
exit $?