shell简介入门之bash编程之流程控制(2)

发表于:2007-07-04来源:作者:点击数: 标签:
F:: while 语法如下: while(condition) do commands done 例如: #!/bin/bash number=0 while(test number -lt 10) do echo "number\c" number=`expr number+1` done echo ----------------------------------------- 结果如下: 0123456789 G:: until 语法

  F::
  while
  语法如下:
  while(condition)
  do
   commands
  done
  例如:
  #!/bin/bash
  number=0
  while(test $number -lt 10)
   do
   echo "$number\c"
   number=`expr $number+1`
  done
  echo
  -----------------------------------------
  结果如下:
  0123456789
  G::
  until
  语法如下:
  until(condition)
  do
   commands
  done
  它和while的不同只在于while是在条件为真时执行循环,而until是在条件为假时执行循环。
  H::
  break及continue
  这两者是用于for,while,until等循环控制下的。break会跳到done后才执行,而continue会跳至
  done后才执行,而continue会跳至done执行,继续执行循环。
  I::
  case
  语法如下:
  case str in
   pat1) commands1;;
   pat2) commands2;;
   pat3) commands3;;
  esac
  而pat除了可以指定一些确定的字符串,也可以指定字符串的集合,如下:
  * 任意字符串
  ?   任意字符
  [abc]  a,b,c三字符其中之一
  [a-n]  从a到n的任一字符
  │    多重选择
  例如:
  test8.sh
  -----------------------------------------------------------
  #!/bin/bash
  echo `enter A,B,C:"
  read letter
  case $letter in
  A│a) echo `you entered A.`;;
  B│b) echo `you entered B.;;
  C│c) echo `you entered C,;;
  *) echo `not a,b,c`;;
  esac
  ---------------------------------------------------------------------- 
  J::
  函数
  格式如下:
  function-name()
  {
   commands
  }
   <br>  而要调用此函数,就像在命令行下直接用命令一般。 <br>  <xmp> <br>  test1() <br>  &#123; <br>   echo`this is fuction 1` <br>  &#125; <br>  test2() <br>  &#123; <br>   echo`this is fuction2` <br>  &#125; <br>  test2 <br>  test1 <br>  ------------------------------------------------------ <br>  运行结果: <br>  this is fuction2 <br>  this is fuction1 <br>  下面是一些常用的shell例子: <br>  例1 给一批文件改名。 <br>  \ls *.c* sed `s/\(.*\).C\(.*\)/mv & \1/` │sh <br>  或者 <br>  for f in *.foo; <br>  fo <br>  base=`basename &#36;f. foo` <br>  mv &#36;f &#36;base.bar <br>  done <br>  例2 将大写文件名发亮写为小心改为小安下心来文件名。 <br>  for f in *;do <br>   mv &#36;f `echo &#36;f│tr `[a-z] ` ][a-z] <br>  done <br>  <br>   <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6352523081585038" crossorigin="anonymous"></script> <p style="font-weight:bold; background-color:#F3F3F3; border:1px solid #DBDBDB; padding:5px; border-radius:5px">原文转自:<a target="_blank" rel="external nofollow">http://www.ltesting.net</a></p> <div class="lt_sec_fenxiang"> <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a title="分享到新浪微博" href="#" class="bds_tsina" data-cmd="tsina"></a><a title="分享到腾讯微博" href="#" class="bds_tqq" data-cmd="tqq"></a><a title="分享到微信" href="#" class="bds_weixin" data-cmd="weixin"></a><a title="分享到QQ空间" href="#" class="bds_qzone" data-cmd="qzone"></a></div> <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"1","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"32"},"share":{},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["tsina","tqq","weixin","qzone"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; </script> </div> <div class="lt_fenye"> <ul class="pagination"> </ul> </div> <div class="ltad_760"> <script type="text/javascript"> /*文章内容页_底部广告_760x90*/ var cpro_id = "u1553971"; </script> <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script> </div> </div> </div> </div> <div class="col-md-3"> <div class="lt_panel"> <div class="lt_panel_head"> <h3> <a href="" class="lt_panel_title">相关文章</a></h3> </div> <div class="lt_panel_body"> <ul> <li> <h5><a target="_blank" href="/ceshi/ruanjianceshikaifajishu/rjcshjdj/unix/linux/2017/0524/208443.html" title="漫画赏析:Linux 内核到底长啥样">漫画赏析:Linux 内核到底长啥样</a></h5> </li> <li class="divider"></li> <li> <h5><a target="_blank" href="/ceshi/ruanjianceshikaifajishu/rjcshjdj/unix/linux/2016/0510/208257.html" title="Linux的进程优先级">Linux的进程优先级</a></h5> </li> <li class="divider"></li> <li> <h5><a target="_blank" href="/ceshi/ruanjianceshikaifajishu/rjcshjdj/unix/linux/2016/0503/208251.html" title="Windows原生运行Linux的技术细节">Windows原生运行Linux的技术细节</a></h5> </li> <li class="divider"></li> <li> <h5><a target="_blank" href="/ceshi/ruanjianceshikaifajishu/rjcshjdj/unix/linux/2014/0226/207097.html" title="Linux常用性能调优工具索引">Linux常用性能调优工具索引</a></h5> </li> <li class="divider"></li> <li> <h5><a target="_blank" href="/ceshi/ruanjianceshikaifajishu/rjcshjdj/unix/linux/2014/0123/207035.html" title="top使用技巧">top使用技巧</a></h5> </li> <li class="divider"></li> <li> <h5><a target="_blank" href="/ceshi/ruanjianceshikaifajishu/rjcshjdj/unix/linux/2014/0123/207034.html" title="bash遍历目录">bash遍历目录</a></h5> </li> <li class="divider"></li> </ul> </div> <div class="img-thumbnail"> <div class="row"> <div class="ltad_270" ><div class="_yyf2re3yyq"></div> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u136320", container: "_yyf2re3yyq", async: true }); </script> <!-- 多条广告如下脚本只需引入一次 --> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" > </script></div> </div> </div> <ul class="nav nav-pills nav-justified panel panel-default ltdiv_index_1_list" style="margin-top:20px; margin-bottom:0px;"> <li class="active"><a href="#v3_tabs_zhou" data-toggle="tab">周排行</a></li> <li><a href="#v3_tabs_yue" data-toggle="tab">月排行</a></li> <li><a href="#v3_tabs_down" data-toggle="tab">下载</a></li> <div class="tab-content" style="padding:10px 10px 20px 10px"> <div class="tab-pane fade in active" id="v3_tabs_zhou"> <ul class="ltdiv1_list_blue"> <li> <h5> <a target="_blank" title="先测试再开发?TDD测试驱动" href="/ceshi/ceshijishu/dycs/dycsff/2023/0701/208794.html">先测试再开发?TDD测试驱动</a> </h5> </li> <li> <h5> <a target="_blank" title="<font color='#FF6633'>全网最详细的接口测试实战</font>" href="/ceshi/ceshijishu/csgl/jccs/2023/0701/208790.html"><font color='#FF6633'>全网最详细的接口测试实战</font></a> </h5> </li> <li> <h5> <a target="_blank" title="自动化测试架构" href="/ceshi/ceshijishu/zdcs/zdcskj/2023/0701/208787.html">自动化测试架构</a> </h5> </li> <li> <h5> <a target="_blank" title="<font color='#FF6633'>软件测试架构师的知识能力</font>" href="/ceshi/ceshijishu/csgl/2023/0701/208788.html"><font color='#FF6633'>软件测试架构师的知识能力</font></a> </h5> </li> <li> <h5> <a target="_blank" title="大数据平台测试方法" href="/ceshi/ceshijishu/yunceshi/2023/0701/208791.html">大数据平台测试方法</a> </h5> </li> <li> <h5> <a target="_blank" title="用不同的测试模型来构建测" href="/ceshi/ceshijishu/dycs/dycsff/2023/0701/208789.html">用不同的测试模型来构建测</a> </h5> </li> <li> <h5> <a target="_blank" title="<font color='#FF6633'>当软件测试遇上ChatGPT:软件</font>" href="/ceshi/ceshijishu/csgl/2023/0701/208793.html"><font color='#FF6633'>当软件测试遇上ChatGPT:软件</font></a> </h5> </li> </ul> </div> <div class="tab-pane fade" id="v3_tabs_yue"> <ul class="ltdiv1_list_green"> <li> <h5> <a target="_blank" title="先测试再开发?TDD测试驱动" href="/ceshi/ceshijishu/dycs/dycsff/2023/0701/208794.html">先测试再开发?TDD测试驱动</a> </h5> </li> <li> <h5> <a target="_blank" title="<font color='#FF6633'>全网最详细的接口测试实战</font>" href="/ceshi/ceshijishu/csgl/jccs/2023/0701/208790.html"><font color='#FF6633'>全网最详细的接口测试实战</font></a> </h5> </li> <li> <h5> <a target="_blank" title="自动化测试架构" href="/ceshi/ceshijishu/zdcs/zdcskj/2023/0701/208787.html">自动化测试架构</a> </h5> </li> <li> <h5> <a target="_blank" title="<font color='#FF6633'>软件测试架构师的知识能力</font>" href="/ceshi/ceshijishu/csgl/2023/0701/208788.html"><font color='#FF6633'>软件测试架构师的知识能力</font></a> </h5> </li> <li> <h5> <a target="_blank" title="大数据平台测试方法" href="/ceshi/ceshijishu/yunceshi/2023/0701/208791.html">大数据平台测试方法</a> </h5> </li> <li> <h5> <a target="_blank" title="用不同的测试模型来构建测" href="/ceshi/ceshijishu/dycs/dycsff/2023/0701/208789.html">用不同的测试模型来构建测</a> </h5> </li> <li> <h5> <a target="_blank" title="<font color='#FF6633'>当软件测试遇上ChatGPT:软件</font>" href="/ceshi/ceshijishu/csgl/2023/0701/208793.html"><font color='#FF6633'>当软件测试遇上ChatGPT:软件</font></a> </h5> </li> </ul> </div> <div class="tab-pane fade" id="v3_tabs_down"> <ul class="ltdiv1_list_red"> <li> <h5> <a target="_blank" title="MBT基于模型的测试介绍资料" href="/ceshi/down/ruanjianceshiziliaoku/rjzlbz/zlkj/2017/0822/208468.html" >MBT基于模型的测试介绍资料</a> </h5> </li> <li> <h5> <a target="_blank" title="iso29119相关介绍性资料" href="/ceshi/down/ruanjianceshiziliaoku/rjzlbz/zlkj/2017/0822/208467.html" >iso29119相关介绍性资料</a> </h5> </li> <li> <h5> <a target="_blank" title="HP QTP 10 中文版官方中文补丁" href="/ceshi/down/shangyeruanjianceshigongju/mercury/gncs/2011/1230/203852.html" >HP QTP 10 中文版官方中文补丁</a> </h5> </li> <li> <h5> <a target="_blank" title="HP QTP 10 英文版 下载地址" href="/ceshi/down/shangyeruanjianceshigongju/mercury/gncs/2011/1230/203851.html" >HP QTP 10 英文版 下载地址</a> </h5> </li> <li> <h5> <a target="_blank" title="HP ALM 11 官方 中文版下载地址" href="/ceshi/down/shangyeruanjianceshigongju/mercury/csgl/2011/1212/203744.html" >HP ALM 11 官方 中文版下载地址</a> </h5> </li> <li> <h5> <a target="_blank" title="Quality Center 9.0中文版 下载地" href="/ceshi/down/shangyeruanjianceshigongju/mercury/csgl/2011/1209/203742.html" >Quality Center 9.0中文版 下载地</a> </h5> </li> <li> <h5> <a target="_blank" title="HttpWatch Basic Edition Version 7." href="/ceshi/down/ruanjianceshifuzhugongju/2011/1028/203418.html" >HttpWatch Basic Edition Version 7.</a> </h5> </li> <li> <h5> <a target="_blank" title="WIN2003+ORACLE11G+QC11(ALM11) 安装" href="/ceshi/down/ruanjianceshiziliaoku/rjcsgjjc/qualityc/2011/0914/203213.html" >WIN2003+ORACLE11G+QC11(ALM11) 安装</a> </h5> </li> <li> <h5> <a target="_blank" title="WIN2003+SQL2005(SP3)+QC11(ALM11) 安" href="/ceshi/down/ruanjianceshiziliaoku/rjcsgjjc/qualityc/2011/0913/203212.html" >WIN2003+SQL2005(SP3)+QC11(ALM11) 安</a> </h5> </li> </ul> </div> </div> </ul> </div> <div class="lt_panel"> <div class="lt_panel_head"> <h3> <a href="" class="lt_panel_title">软件测试沙龙</a> <a href="" class="lt_panel_right">More>></a> </h3> </div> <div class="lt_panel_body" style="padding-top:8px;"> <script src='/plus/ad_js.php?aid=89' language='javascript'></script> <script src='/plus/ad_js.php?aid=88' language='javascript'></script> <script src='/plus/ad_js.php?aid=87' language='javascript'></script> </div> </div> <div class="lt_panel"> <div class="lt_panel_head"> <h3> <a href="" class="lt_panel_title">新浪微博</a><a href="http://weibo.com/lingceguoji/" class="lt_panel_right">More>></a></h3> </div> <div class="lt_panel_body"> <iframe width="100%" height="420" class="share_self" frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=450&fansRow=2&ptype=1&speed=0&skin=9&isTitle=0&noborder=0&isWeibo=1&isFans=0&uid=2190735247&verifier=72498178&dpc=1"></iframe> </div> </div> <a href="http://list.qq.com/cgi-bin/qf_invite?id=d65cee510a8ba9ca33d848537766a9aaef05a7b11e8544ef" title="邮件订阅"><img src="/images/gagd/2014/05/big_youjiandingyue.png" alt="..." width="270" height="124" class="img-thumbnail"></a> <div class="lt_panel_head"> <h3> <a href="" class="lt_panel_title">热门标签</a> </h3> </div> <div class="lt_panel_body"> <ul class="lt_sec_list_top" style="height:120px"> <li><a href="/ceshi/ceshijishu/gncs/">功能测试</a></li> <li><a href="/ceshi/ceshijishu/xncs/">性能测试</a></li> <li><a href="/ceshi/ceshijishu/aqcs/">安全测试</a></li> <li><a href="/ceshi/ceshijishu/bdhcs/">本地化测试</a></li> <li><a href="/ceshi/ceshijishu/yxcs/">游戏测试</a></li> <li><a href="/ceshi/ceshijishu/webcs/">web测试</a></li> <li><a href="/ceshi/ceshijishu/dycs/">单元测试</a></li> <li><a href="/ceshi/ceshijishu/mjcs/">敏捷测试</a></li> <li><a href="/ceshi/ceshijishu/csyl/">测试用例</a></li> <li><a href="/ceshi/ceshijishu/csmb/">测试模版</a></li> <li><a href="/ceshi/ceshijishu/csgl/">测试管理</a></li> <li><a href="/ceshi/ceshijishu/csgj/">测试工具</a></li> </ul> <div class="lt_dec_weixin"> <script src='/plus/ad_js.php?aid=103' language='javascript'></script> <ul> <li><a title="新浪微博" href="http://weibo.com/2190735247/"><img src="/images/icon/icons_sinaweibo.png"></a></li> <li><a title="腾讯微博" href="http://e.t.qq.com/ltesting-net"><img src="/images/icon/icons_qqweibo.png"></a></li> <li><a title="邮件订阅" href="http://list.qq.com/cgi-bin/qf_invite?id=d65cee510a8ba9ca33d848537766a9aaef05a7b11e8544ef"><img src="/images/icon/icons_youjiandingyue.png"></a></li> <li style="margin-right:0"><a title="RSS订阅" href="/rss.xml"><img src="/images/icon/icons_rss.png"></a></li> </ul> </div> </div> </div> </div> <div class="row"> <div class="footer" style="text-align:center"> <div id="bottom_link"><a rel="external nofollow" href="/about/aboutus.html" target="_blank">关于领测软件测试网</a> | <a href="/about/zhaopin.html" rel="external nofollow" target="_blank">诚聘英才</a> | <a rel="external nofollow" href="/about/adserver.html" target="_blank">广告服务</a> | <a href="/about/tougao.html" rel="external nofollow" target="_blank">投稿指南</a> | <a rel="external nofollow" href="/about/contactus.html" target="_blank">联系我们</a> | <a href="/about/map.html" target="_blank">网站地图</a>| <a rel="external nofollow" href="/about/links.html" target="_blank">友情链接</a><br /> 版权所有(C) 2003-2021 Ltesting(<a href="http://www.ltesting.net/" target="_blank">领测软件测试网</a>)|<a href="http://www.ltesting.com.cn/" target="_blank">领测国际科技(北京)有限公司</a> |<a href="http://www.ltesting.cn/" target="_blank">软件测试培训网</a> All Rights Reserved<br /> <a href="https://beian.miit.gov.cn/" target="_blank">京ICP备2023014753号-2</a> | 京公网安备11010602004416号-1<br /> 技术支持和业务联系:info@ltesting.com.cn 电话:010-51297073<br /> <BR> <script type="text/javascript"> //initiating jQuery jQuery(function($) { $(document).ready( function() { //enabling stickUp on the '.navbar-wrapper' class $('.yidongnav').stickUp({ //enabling marginTop with the 'auto' setting marginTop: 'auto' }); }); }); $(function() { $('.banner').unslider( {speed: 800, delay: 6000, complete: function() {}, keys: true, dots: true, fluid: false } ); }); </script> <!--网站统计代码开始--> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-TF24PCFVLE"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-TF24PCFVLE'); </script> <script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script> <script>LA.init({id:"20OY1Li5zIFeSFLo",ck:"20OY1Li5zIFeSFLo"})</script> <script type="text/javascript"> var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F207c370227bbf98ebb229202aa7f0481' type='text/javascript'%3E%3C/script%3E")); </script> <!--网站统计代码结束--> </div> </div> </div> </div> </div> </body> </html>