TA的每日心情 | 开心 2016-5-12 14:23 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
This topic is about the While Loop on Unix/Linux bash environment. Following is the sample:
! I; P) ^/ B& f1 f% `7 D m- |6 G& P! e& z5 ~- ?' o6 Y
while [ condition ]
, q0 Y C7 {4 M! B; k. r9 @" Ido! k) r8 q4 }) o L
command1. K9 n: U/ C1 k: L- f W
command2/ D6 V" K" k- }) B' l
command34 |& q: s J$ l. S( X
if [ condition ]. \ B8 W% R j4 m
command11 n- D8 J2 T: @ ?- z
fi: J# c5 J' a% w% x7 t; z
done, D: G; I& G, X( Y* {. w
7 s: |! l3 n# m5 U) b- J- u
5 F9 e0 ^7 t; J
-------------------------
* Z4 W( a- v( A. s# t#!/bin/bash
3 w. r1 |) x6 {4 h5 [+ | ix=1( [- D) M3 l0 m. K& q
while [ $x -le 5 ]
! w# c$ }, j/ h9 F; _do
' o" }0 o& M( s' k echo "Welcome $x times"- [* X# l& g. q* |8 |, h( W& ^
x=$(( $x + 1 ))2 u" S% Q- `& b& S) U
done
( c& g1 p, Q9 b6 x# D" o9 e/ M3 Y% W) M7 G* v& \6 @
-------------------------) r1 `- c3 X: S( H1 d
result will be like this:
0 E! I9 E. b2 I5 g3 `' n2 t/ S' k/ B m
Welcome 1 times
4 a7 w- R$ L' b" D1 iWelcome 2 times
4 {7 Z9 h- Q* t' u8 JWelcome 3 times
- ~# a" M o2 KWelcome 4 times
3 W; g" N Y8 ?Welcome 5 times. w3 y- M' Q: Y
9 E" P/ V l% Y s' D1 T |
|