What is your method for invoking SQL from shell scripts? If you can provide a few details about that, i might have some suggestions.
I wrote a C program that uses ct-lib to submit database commands from the shell environment, and return status explicitly returned by procedures/commands are returned to the shell via the return statement in the C program.
The problem is that @@error can have more values than the $? shell variable can handle. $? can deal with values 0-255, where @@error can be the range of signed int values.