How can you run a command in bash over until success

前端 未结 6 806
走了就别回头了
走了就别回头了 2020-11-28 19:10

I have a script and want to ask the user for some information, the script cannot continue until the user fills in this information. The following is my attempt at putting a

6条回答
  •  时光取名叫无心
    2020-11-28 19:41

    If anyone looking to have retry limit:

    max_retry=5
    counter=0
    until $command
    do
       sleep 1
       [[ counter -eq $max_retry ]] && echo "Failed!" && exit 1
       echo "Trying again. Try #$counter"
       ((counter++))
    done
    

提交回复
热议问题