So a script is working properly (tested many times) , then you add a new fine piece of code ,finaly its fails generally with a syntax error at the last line of the script.
This is not a particular Issue ,in fact i noticed this behavior with different scripts, all with may lines and complicated workflow, generaly the scripts fails with sintax error at the last line of the code but if you trace de logs , all the job is done.
If the script is fully charged in the machine's memory , wHow Could This Be Happening ?
Shell scripts do not support dynamic changes during execution. If you ignore this restriction you will get unpredicable results. Shells tend to read their scripts as needed, but using large buffers. Also ksh compiles a script dynamically during execution but it may not do this if you are tracing.