bash localize variable
build script output; refactoring