The return code for the test is being sucked in by if so doing the echo of return code in your then is meaningless.
You'd have to do something like:
Code:
str1="GOOd boy"
str2="Bad boy"
if test "$str1" = "$str2"
then echo 0
exit 0
else echo 1
exit 1
fi
The echo is literal (0 = true, 1 = false) rather than being something you got from the if itself. The "then" occurs when it is "true" so doing the literal echo there is OK. You can then set the return code (exit status) within the then or within the else so the overall script exits with the return code you want. If you run the above script then run "echo $?" at command line immediately it will show you "1".