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:' [7 D6 E- K. [. `
! D" A" V) o8 O4 U8 H3 W+ f0 {4 L7 Iwhile [ condition ]4 _4 D# N4 V- T$ n I w& ?
do. V9 v/ K/ C9 |1 [
command18 h7 M1 W% D: W' d# M- [# q
command2
& G) b, r' ]6 |3 c1 q5 d command3! n+ t/ U+ J5 v/ [: d3 a/ _+ R1 N
if [ condition ]/ m/ P: ~- N+ S1 Y6 N8 S- o% d! {
command1 s% c" t7 q2 i8 _) b$ U
fi, y5 |$ q3 A- g$ ?- @
done
6 ^& @! Q4 U# F/ u
& b+ m6 ?3 ?0 F+ U: v0 r4 Y
) H* t; v3 U" T- u( T6 P* |-------------------------6 y" `0 }8 Q1 e+ N6 o- Z% i% {
#!/bin/bash" h- ?6 b& b! P1 Q2 N7 W; y. S8 z
x=1# l8 Q; N" j8 T2 h
while [ $x -le 5 ]
7 D7 p+ R( Z+ N. Z! A9 ydo! K: G; G; C! Q) ~3 P6 i- S
echo "Welcome $x times"
, x5 Q/ d3 w% ]2 [# d: i* C x=$(( $x + 1 ))- I6 q! O2 B4 n2 c; `, e
done
, |- h9 q- v1 U; d8 L0 b# R6 }/ Q5 [* Z& c: W/ D
-------------------------
/ p3 s0 \ C$ ^4 a8 `4 y) \result will be like this:
t3 }1 Y1 k9 I1 K: c
5 Q) @1 N5 k( k- V3 |2 Z( OWelcome 1 times9 K5 \; L0 r& N7 q
Welcome 2 times
9 E: X$ L1 P* c; L1 dWelcome 3 times
, \% B, B& Y5 H* g8 |/ LWelcome 4 times
" f( E5 Z3 f0 f! Y9 s QWelcome 5 times9 {. b; U6 |, P8 `7 Y6 _
B0 d. K: q; h! e; j* ~ |
|