This MR improves all scripts by following bash best practices and also improving functionality where appropriate.