• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-7-04 12:06 | 作者: admin | 来源:  网友评论 | 查看: 10次 | 进入软件测试论坛讨论

领测软件测试网
  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>   <p> <div> <div style="width:680px; height:200px; margin-top:10px; margin-bottom:10px;"> <div style="height:20px; width:678px; background:#eaeff4; margin:0px; border-top:1px #cccccc solid; border-left:1px #cccccc solid; border-right:1px #cccccc solid; float:left;"><span style="margin-left:10px; font-weight:bold; line-height:32px; margin-top:3px;">延伸阅读</span></div> <div style="margin:0px; border:1px #cccccc solid; float:left"> <table width="678" border="0" cellspacing="2" cellpadding="2"> <tr> <td style="line-height:40px;"> <div class="_xopyhmxspgf"></div> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u6924735", container: "_xopyhmxspgf", async: true }); </script> <!-- 多条广告如下脚本只需引入一次 --> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" > </script> </td> <td style="line-height:40px;"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6352523081585038" crossorigin="anonymous"></script> </td> </tr> </table> </div> </div> </div> </p> <p>文章来源于<a href="https://www.ltesting.net/" target="_blank">领测软件测试网</a> <a href="https://www.ltesting.net/" target="_blank">https://www.ltesting.net/</a><p> <!--google 搜索 广告代码 开始--> <script type="text/javascript"><!-- google_ad_client = "pub-6352523081585038"; google_ad_format = "js_sdo"; google_searchbox_width = 215; google_searchbox_height = 26; google_link_target = 2; google_logo_pos = "left"; google_ss_domains = "www.ltesting.net"; google_ad_height = 90; google_ad_width = 500; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_sdo.js"> </script> <!--google 搜索 广告代码 结束--> <p> </div> <div class="mt10"><span class="gobbs"><a href="http://bbs.ltesting.net" target="_blank">软件测试论坛</a></span><p class="pd8t"><script type="text/javascript" src="http://www.jiathis.com/code/jiathis.js" charset=utf-8></script></p></div> </div> <!--相关文章--> <div class="wd100 mt10 fl"> <div class="w345 fl mr10"> <div class="xgtit"><a href="https://www.ltesting.net/" target="_blank">领测软件测试网</a>最新更新</div> <div class="xgcon"> <ul class="tlist"> <li><a href="https://www.ltesting.net/html/70/n-199870.html">数据库中Linux内核的ioctl函数学习</a></li> <li><a href="https://www.ltesting.net/html/06/n-199806.html">软件测试中多种测试linux内核的方法</a></li> <li><a href="https://www.ltesting.net/html/54/n-199654.html">软件测试中oracle 10g for linux安装</a></li> <li><a href="https://www.ltesting.net/html/89/n-199289.html">软件测试中Linux内核模块介绍</a></li> <li><a href="https://www.ltesting.net/html/88/n-199288.html">软件测试中Linux系统线程编程</a></li> </ul> </div> </div> <div class="w350 fl"> <div class="xgtit"><a href="https://www.ltesting.net/html/news.html" target="_blank">软件测试技术</a>相关文章</div> <div class="xgcon"> <ul class="tlist"> <li><a href="https://www.ltesting.net/html/10/n-202110.html" target="_blank" title="oracle数据库性能检测工具 statspack安装和说明">oracle数据库性能检测工具 statspack安装和说明</a></li> <li><a href="https://www.ltesting.net/html/09/n-202109.html" target="_blank" title="GUI测试经验小结">GUI测试经验小结</a></li> <li><a href="https://www.ltesting.net/html/08/n-202108.html" target="_blank" title="oracle性能Statspack使用之命中率调整">oracle性能Statspack使用之命中率调整</a></li> <li><a href="https://www.ltesting.net/html/07/n-202107.html" target="_blank" title="测试用例的编写规范">测试用例的编写规范</a></li> <li><a href="https://www.ltesting.net/html/06/n-202106.html" target="_blank" title="Twitter和Netflix架构师QCon北京演讲:性能优化原则和基于云计算构建Netflix">Twitter和Netflix架构师QCon北京演讲:性能优化...</a></li> </ul> </div> </div> </div> <!--/相关文章--> <div class="ggleadsense mt10"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6352523081585038" crossorigin="anonymous"></script> </div><br> </div> <div class="w280 fl"> <div class="ad_conr"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6352523081585038" crossorigin="anonymous"></script> </div> <!--开课信息--> <div class="mt10 bc"> <div class="artit"><a href="https://www.ltesting.net/" target="_blank">软件测试培训</a>信息</div> <div class="arcon"> <ul class="tlist"><li><a href="https://www.ltesting.net/viewnews-201261">【就业】11年一月份就业班热招中</a></li> <li><a href="https://www.ltesting.net/viewnews-201260">【就业】10年十二月份就业班插班中</a></li> <li><a href="https://www.ltesting.net/html/05/n-143705.html">【提高】性能测试应用-LR</a></li> <li><a href="https://www.ltesting.net/html/04/n-143704.html">【提高】自动化测试-QTP</a></li> </ul> </div> <div><script language="javascript"> if(document.all || document.getElementById) { document.write('<span id="LR_User_Icon0"></span>'); } else if(document.layers) { document.write('<layer name="LR_User_Icon0"></layer>'); } </script></div> </div> <!--/开课信息--> <!--最新专题--> <div class="mt10 bc"> <div class="artit">最新<a href="https://www.ltesting.net/html/89/category-catid-189.html" target="_blank">软件测试技术专题</a></div> <div class="arcon"><ul class="tlist"> <li><a href="https://www.ltesting.net/viewnews-170458">【专题】VSTS2010软件测试技术.</a></li> <li><a href="https://www.ltesting.net/viewnews-168102">【专题】软件测试用例设计方法</a></li> <li><a href="https://www.ltesting.net/html/47/n-166647.html">【专题】软件自动化测试框架专题</a></li> <li><a href="https://www.ltesting.net/html/33/n-159933.html">【专题】LoadRunner专题系列—.</a></li> <li><a href="https://www.ltesting.net/html/52/n-159352.html">【专题】LoadRunner脚本中的协.</a></li> <li><a href="https://www.ltesting.net/html/79/n-159079.html">【专题】LoadRunner脚本录制设置</a></li> <li><a href="https://www.ltesting.net/html/71/n-158171.html">【专题】LoadRunner脚本录制</a></li> <li><a href="https://www.ltesting.net/html/37/n-157637.html">【专题】LoadRunner脚本实例</a></li> </ul> </div> </div> <!--/最新专题--> <!--最新新闻--> <div class="bc mt10"> <div class="artit">最新<a href="https://www.ltesting.net/html/81/category-catid-181.html" target="_blank">领测软件测试网新闻</a></div> <div class="arcon"> <ul class="tlist"><li><a href="https://www.ltesting.net/html/75/n-188075.html">领测国际完成为期四天的高级软件测试实...</a></li> <li><a href="https://www.ltesting.net/html/73/n-188073.html">领测国际圆满完成《高级软件测试技术》...(图)</a></li> <li><a href="https://www.ltesting.net/html/06/n-202106.html">Twitter和Netflix架构师QCon北京演讲:...</a></li> <li><a href="https://www.ltesting.net/html/05/n-202105.html">第五届中国软件质量年会即将召开</a></li> <li><a href="https://www.ltesting.net/html/84/n-202084.html">2011年2月编程语言排行榜(图)</a></li> <li><a href="https://www.ltesting.net/html/74/n-202074.html">第2届 ATI 获奖的软件自动化测试工具</a></li> <li><a href="https://www.ltesting.net/html/65/n-202065.html">2011年将改变搜索市场局面的10件事(图)</a></li> <li><a href="https://www.ltesting.net/html/27/n-202027.html">黄石公园火山恐临近喷发 将横扫美国2/...(图)</a></li> </ul> </div> </div> <!--/最新新闻--> <div class="mt10"><div class="_32yzqetq8nh"></div> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u136344", container: "_32yzqetq8nh", async: true }); </script> <!-- 多条广告如下脚本只需引入一次 --> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer" > </script> </div> <!--排行--> <div class="bc" style="margin-top:13px"> <div class="artit">软件测试技术文章排行榜</div> <ul class="phli"> <li class="tag01" id="tag_1_b1" onMouseOver="return swap_tag_1_(1)">编辑推荐</li> <li class="tag02" id="tag_1_b2" onMouseOver="return swap_tag_1_(2)">周排行</li> <li class="tag02" id="tag_1_b3" onMouseOver="return swap_tag_1_(3)">月排行</li> </ul> <div class="arcon" id="tag_1_1" style="display:block;"> <ul class="tlist"> <li><a href="https://www.ltesting.net/html/00/n-202100.html">软件测试点列表和模块功能树(图)</a></li> <li><a href="https://www.ltesting.net/html/99/n-202099.html">43个日常测试功能点</a></li> <li><a href="https://www.ltesting.net/html/98/n-202098.html">web登录用户名/密码/验证码测试设计...</a></li> <li><a href="https://www.ltesting.net/html/97/n-202097.html">网络游戏性能测试方案</a></li> <li><a href="https://www.ltesting.net/html/96/n-202096.html">软件性能测试需求点总结</a></li> <li><a href="https://www.ltesting.net/html/92/n-202092.html">你为什么要做自动化测试</a></li> <li><a href="https://www.ltesting.net/html/91/n-202091.html">软件测试自动化:时机成熟再上马</a></li> <li><a href="https://www.ltesting.net/html/90/n-202090.html">使用 IBM Rational Functional Test...(图)</a></li> </ul> </div> <div class="arcon" id="tag_1_2" style="display:none;"> <ul class="tlist"> <li><a href="https://www.ltesting.net/html/96/n-202096.html">软件性能测试需求点总结</a></li> <li><a href="https://www.ltesting.net/html/92/n-202092.html">你为什么要做自动化测试</a></li> <li><a href="https://www.ltesting.net/html/99/n-202099.html">43个日常测试功能点</a></li> <li><a href="https://www.ltesting.net/html/94/n-202094.html">基于测试用例的功能测试</a></li> <li><a href="https://www.ltesting.net/html/03/n-202103.html">软件测试方法大全</a></li> <li><a href="https://www.ltesting.net/html/95/n-202095.html">常用的功能测试方法</a></li> <li><a href="https://www.ltesting.net/html/01/n-202101.html">经典的杯子测试题</a></li> <li><a href="https://www.ltesting.net/html/00/n-202100.html">软件测试点列表和模块功能树(图)</a></li> </ul> </div> <div class="arcon" id="tag_1_3" style="display:none;"> <ul class="tlist"> <li><a href="https://www.ltesting.net/html/71/n-202071.html">一位软件测试工程师的软件测试工作技...</a></li> <li><a href="https://www.ltesting.net/html/02/n-202002.html">Android手机系统的性能测试工具</a></li> <li><a href="https://www.ltesting.net/html/29/n-202029.html">QTP自动化测试过程随想</a></li> <li><a href="https://www.ltesting.net/html/84/n-202084.html">2011年2月编程语言排行榜(图)</a></li> <li><a href="https://www.ltesting.net/html/27/n-202027.html">黄石公园火山恐临近喷发 将横扫美国...(图)</a></li> <li><a href="https://www.ltesting.net/html/25/n-202025.html">Facebook的软件工程师是怎样开发软件...</a></li> <li><a href="https://www.ltesting.net/html/98/n-201998.html">Android手机测试的自动化测试工具</a></li> <li><a href="https://www.ltesting.net/html/95/n-201995.html">基于QTP和QC的自动化测试框架(图)</a></li> </ul> </div> </div> <!--/排行--> <!--分类最新内容--> <div class="bc mt10"> <div class="artit">软件测试技术分类最新内容</div><div class="arcon"> <ul class="tlist"> <li><a href="https://www.ltesting.net/html/70/n-199870.html">数据库中Linux内核的ioctl函数学习</a></li> <li><a href="https://www.ltesting.net/html/06/n-199806.html">软件测试中多种测试linux内核的方法</a></li> <li><a href="https://www.ltesting.net/html/54/n-199654.html">软件测试中oracle 10g for linux安装</a></li> <li><a href="https://www.ltesting.net/html/89/n-199289.html">软件测试中Linux内核模块介绍</a></li> <li><a href="https://www.ltesting.net/html/88/n-199288.html">软件测试中Linux系统线程编程</a></li> <li><a href="https://www.ltesting.net/html/71/n-187971.html">软件测试中Linux核心介绍以及编译</a></li> <li><a href="https://www.ltesting.net/html/19/n-183819.html">在软件测试环境Linux中教你如何安装...</a></li> <li><a href="https://www.ltesting.net/html/08/n-172008.html">测试Linux的可靠性(图)</a></li> </ul> </div> </div> <!--/分类最新内容--> <div class="mt10"><div class="_r2u9n69788"></div> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u136320", container: "_r2u9n69788", async: true }); </script> </div> </div> </div> <div class="adbox"><a href="https://www.istqb.org.cn/" target="_blank"><img src="https://www.ltesting.net/xc/istqb-775-90.jpg" /></a></div> <script language="javascript" type="text/javascript"> <!-- addMediaAction('articlebody'); addImgLink("articlebody"); //--> </script> <!-- Footer --> <div class="content mt10 fl"> <div class="bc pd10 copy"> <a href="https://www.ltesting.net/about/about.html" target="_blank">关于领测软件测试网</a> | <a href="https://www.ltesting.net/about/hezuo.html" target="_blank">领测软件测试网合作伙伴</a> | <a href="https://www.ltesting.net/about/ad.html" target="_blank">广告服务</a> | <a href="https://www.ltesting.net/about/tougao.html" target="_blank">投稿指南</a> | <a href="https://www.ltesting.net/about/contact.html" target="_blank">联系我们</a> | <a href="https://www.ltesting.net/action/site/type/map" target="_blank">网站地图</a> | <a href="https://www.ltesting.net/action/site/type/link" target="_blank">友情链接</a><br /> 版权所有(C) 2003-2010 TestAge(<a href="https://www.ltesting.net/" target="_blank">领测软件测试网</a>)|<a href="http://www.ltesting.com.cn/" target="_blank">领测国际科技(北京)有限公司</a>|<a href="https://www.ltesting.net/" target="_blank">软件测试工程师培训网</a> All Rights Reserved<br /> 北京市海淀区中关村南大街9号北京理工科技大厦1402室 <a href="http://www.miibeian.gov.cn" target="_blank">京ICP备2023014753号-2</a><br /> 技术支持和业务联系:info@testage.com.cn 电话:010-51297073<br /> </div> <br /> <!-- 网站次导航 --> <center> <A title="" href="https://www.ltesting.net/">软件测试</A>&#160;|&#160;<A title="" href="http://www.ltesting.com.cn/">领测国际</A> |&#160;<A title="" href="https://www.istqb.org.cn/">ISTQB</A> |&#160;<A title="" href="https://www.istqb.net.cn/">ISTQB官网</A> |&#160;<A title="" href="https://www.tmmi.org.cn/">TMMi</A> |&#160;<A title="" href="https://www.tmmi.org.cn/">TMMi认证</A> |&#160;<A title="" href="https://www.istqb.org.cn/">国际软件测试工程师认证</A> |&#160;<A title="" href="https://www.ltesting.net/">领测软件测试网</A> </center> </div><br> </div> <!-- /Footer --> <!--网站统计代码开始--> <!-- 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> <!--网站统计代码结束--> </body> </html> <script language="javascript"> <!-- var Modified = new Date(document.lastModified); var copyright = document.getElementById("xspace-copyright"); if(copyright) { copyright.innerHTML += "Last update: <a href=\"https://www.ltesting.net/index.php?action/viewnews/itemid/125034/page/1/php/1\" title=\"点击可以立即更新本页面\">"+(Modified.getYear()<200?(Modified.getYear()+1900):Modified.getYear())+"-"+(Modified.getMonth()+1)+"-"+Modified.getDate()+" "+Modified.getHours()+":"+Modified.getMinutes()+":"+Modified.getSeconds() + "</a><br>"; } document.write('<script src="https://www.ltesting.net/batch.html.php?code=http%253A%252F%252Fwww.ltesting.net%252Findex.php%253Faction%252Fviewnews%252Fitemid%252F125034%252Fpage%252F1%2F1298183316%2F86400%2F0%2F125034%2Fviewnews&amp;lastmodified=' + Modified.getTime() + '" type="text\/javascript" language="javascript"><\/script>'); //--> </script>