Thanks Allen Wittenauer for the detailed reviews!
Patch 2 addresses most of your comments. The only difference is that I extracted 2 functions, to escape sed and xml separately. They could be of general use.
I manually verified the scripts work by just executing the scripts with correct env vars. (Didn't find any example in our code or the docs about how shell unit tests are done in hadoop... Please feel free to share your thoughts)