Create a bash function to reduce code duplication