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:
( L5 }) o% q* ~3 T& e: W. m% [( k7 H C& d6 u5 @2 u& r
while [ condition ]+ D% i' C' K* @2 Y: O
do. [+ O( _5 q% {3 c+ ?5 A0 P. N
command1
M& m/ r# v, K: f( Y command2
# q% l& o& K# k6 T! \4 W command3
% C6 m* h% H q+ O6 L if [ condition ]
/ H; j1 L v7 J command1* d! L! D, u& J) _1 m% o6 o
fi' P4 \6 i8 h$ O4 x5 ` W
done; d3 \' C( }/ n& u; G( [ I
1 {6 M4 u1 t; M! f
+ F3 A. A3 f( d- [" F7 j, w-------------------------
9 ^$ U" M/ ^0 B5 t! s- V- c3 a#!/bin/bash
- j3 B' g. a/ m4 |, g# y- dx=1
( [, Q4 E: Q% b6 Vwhile [ $x -le 5 ]
" n$ E/ ]+ @5 R2 W7 K8 N6 P9 C7 Pdo6 V+ `. J4 p4 J4 o( q% N+ _
echo "Welcome $x times") L L+ O4 h' V, {9 A7 c# H/ z# p
x=$(( $x + 1 ))) ~% u# I: Z$ n2 v4 ?! a# x
done+ E7 X8 z6 t3 F# o% G* n% m- E
2 b0 I, l, x" {
-------------------------& o1 p9 C& v9 x* y' C
result will be like this:
+ O ] z! d% \% f9 i1 F4 M+ e2 s( U" H5 K
Welcome 1 times* d2 G% `1 b4 B3 q3 |) w/ k9 ]
Welcome 2 times/ L( v7 l3 H6 Q2 k& m
Welcome 3 times2 B; s N4 w% B0 I" `
Welcome 4 times
/ j4 x/ R" A# P! G6 [/ xWelcome 5 times+ N' M- k* _9 [3 |* X- u
% G! ^$ ~ a: S7 u/ _' m5 V |
|