Limit bash while loop to 10 retries

前端 未结 4 1316
滥情空心
滥情空心 2021-01-12 07:34

How can this while loop be limited to maximum 10 retries?

#!/bin/sh
while ! test -d /somemount/share/folder
do
    echo \"Waiting for mount /somemount/share/         


        
4条回答
  •  清酒与你
    2021-01-12 07:58

    Keep a counter:

    #!/bin/sh
    
    while ! test -d /somemount/share/folder
    do
        echo "Waiting for mount /somemount/share/folder..."
        ((c++)) && ((c==10)) && break
        sleep 1
    done
    

提交回复
热议问题