shell: Reduce code duplication