To see where a script produces an error use the command:
sh -x script argument
The -x option to the sh command tells it to print commands and their arguments as they are executed.
You can then see what stage of the script has been reached when an error occurs.