Yes, actually, the other answer you got was wrong.
Just throw an error inside the script, probably (given what you want to do) at the end. For example:
osascript -e 'error "This is a test." number 9000'
on the command line will give (on the command line) something like:
6:22: execution error: This is a test (-128)
If you read the man page for osascript, you will see that by default script errors are written to stderr; if you have your shell script watch stderr between the start of the script and the end of it, you'll catch the result message.
A few things to keep in mind:
--> AppleScript can catch its own errors using a "try" block, similar to in other languages. The basic syntax is:
try
(* Do some stuff here *)
on error msg number num
(* Process the error here *)
end try
--> If you throw an error yourself, try to use an error number which is "safe". Most of the negative numbers are already in use as standard signals. For example, -128 is "User canceled", while -43 is "file not found" (which pops up if you cast a string to an alias and the string does not describe a path to a valid item in the filesystem -- that's actually a very simple way to test for file existence). If you use numbers starting with 9000, which seems to be the consensus starting point, then you have the additional advantage of being able to figure out where things went wrong.