Shell Scripts loop (loop)

一、while……do……done

  When the judgment condition is satisfied, a cycle until the condition is not satisfied stopped

the while [the determination condition]
 do    # cycle start 
    block 
done     End cycle #

 

二、until……do……done

  And while do done contrary, stop the loop when the condition is true, otherwise the cycle continues

an until [the determination condition]
 do    # cycle start 
    block 
done     End cycle #

 

Three, for ...... do ...... done (fixed number of cycles)

  The method has been determined that the number of cycles in the cycle

for the variable name in variable contents 1 2 variable variable content content ... 3
 do 
    block 
done

  The above procedure, when the cycle as follows:

  1. The first loop, the variable name -------> variable content 1;

  2. The second cycle, the variable name -------> Variable contents 2;

  3. The third cycle, the variable name -------> 3 variable content;

  4. The first N cycles, variable name -------> N content variable;

四、for……do……done

for ((initial value; restrictions; performed N times))
 do 
    block 
done

  Description: 1. Initial value: an initial cycle of the variable data which, for example, i = 1;

        2, Constraints: variable value has been circulated within limits, for example, i <10;

        3, the N-th performed: one cycle do not, change variables, such as i = i + 1;

Guess you like

Origin www.cnblogs.com/shimc/p/11271599.html