查看: 1734|回复: 0
打印 上一主题 下一主题

Bash While Loop

[复制链接]
  • TA的每日心情
    开心
    2016-5-12 14:23
  • 签到天数: 2 天

    [LV.1]初来乍到

    跳转到指定楼层
    楼主
    发表于 2014-4-17 11:48:24 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
    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
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    小黑屋|Archiver|手机版|香港易事泊讨论区论坛 - bbs.hkesp.com    

    © 2001-2013 Comsenz Inc.All Rights Reserved.

    Powered by Discuz! X3.2

    快速回复 返回顶部 返回列表