There are many cases in which you may wish to retry a failed command a certain number of times. Examples are database failures, network communication failures or file IO problems. The snippet below shows a simple method of retrying commands in bash: #!/bin/bash MAX_ATTEMPTS=5 attempt_num=1 until command || (( attempt_num == MAX_ATTEMPTS )) do echo "Attempt $attempt_num failed! Trying again in $att