Shell中的while和until循环

 时间:2024-10-12 07:00:57

Shell中不仅有for循环,还有while和until循环。

工具/原料

CentOS 7.2

while循环

1、while循环用于不断执行一系列命令,也用于从输入文件中读取数据;命令通常为测试条件。其格式为:while commanddo Statement(s) to be executed if command is truedone命令执行完毕,控制返回循环顶部,从头开始直至测试条件为假。

Shell中的while和until循环

3、while循环可用于读取键盘信息。下面的例子中,输入信息被设置为变量FILM,按<Ctrl-D>结束循环。echo 'type <CTRL-D> to terminate'echo -n 'enter your most liked film: 'while read FILMdo echo "Yeah! great film the $FILM"done

Shell中的while和until循环

2、例如,使用 until 命令输出 0 ~ 9 的数字:#!/bin/basha=0until [ ! $a -lt 10 ]do echo $a a=`expr $a + 1`done

Shell中的while和until循环
  • 血饮传说快速赚取金币方法指南
  • DNF怎么生产冰晶石?
  • dnf90史诗钝器世界的支点怎么样哪里爆率高?
  • 怎样重装显卡驱动
  • 热门搜索
    蒸米饭怎么做好吃 怎么找货源 家常炒菜的做法大全 心悦会员成长值怎么算 我的世界怎么做梯子 风疹的治疗方法 炖羊肉的家常做法 家常炖鱼 月季花的扦插方法 端口映射怎么设置