I have to look up this one frequently, because it is really helpful.
If you want to see what lines of a shell script are actually executed, place this line in your code:
[shell]set -x [/shell]
I usually do that after the funny thing called Shebang (#!/bin/bash – I can also never remember this one correctly), but surely you can place it right before the section where you expect the problem. If you have an idea where the problem might be, that is. If not, just start from the beginning.
Cool thing: the variables are replaced in the output, or as the man page puts it:
Print a trace of simple commands and their arguments after they are expanded and before they are executed