The real problem here is that a multi-hundred-line script was written in bash. While bugs can happen in any language, this particular error was due to a bash-specific pitfall, and bash has <i>many</i> such pitfalls. Bash is really only suitable for interactive use, or for bootstrapping the install of another scripting language.