Doing bash the ruby way. Some refactoring.