Russell Coker writes about shellscripts. I have a different suggestion. Whenever you think that a shellscript is the right solution to a problem, you are mistaken: do it in a proper scripting language instead. Having access to proper data structures will mean you don't have to contort your code to fit values into scalar strings, or write loads of temporary files, or call cut/awk/sed/grep etc. repeatedly on the same inputs to get at different fields, etc. etc. etc.
I reckon nine times out of ten it's the right decision. But when you just have
to use a shellscript, use
set -e (as Andrew Pollock points out, this is
safer than putting it on the hashbang