点击返回 自学Linux命令行与Shell脚本之路 12.5-while.until命令 until 循环与 while 循环在处理方式上刚好相反. while循环用于不断执行一系列命令,也用于从输入文件中读取数据(条件成立则循环,不成立则停止循环) until 循环执行一系列命令直至条件为 true 时停止.(条件成立则停止循环 ,不成立则循环) 1.while命令 while condition do command done condition的退出状态码必须随着循环中运行的命令而改变.…
写在前面:案例.常用.归类.解释说明.(By Jim)使用if-then语句如果命令的退出状态是0(成功执行命令),将执行then后面的所有命令.如果命令的退出状态是0以外的其他值,那么then后面的命令将不会执行,bash shell会移动到脚本的下一条命令. #!/bin/bash # testing the if statement if date then echo "it worked" fi (date返回0,执行then语句it worked) #!/bin/bash #…
写在前面:案例.常用.归类.解释说明.(By Jim) for命令重复一系列的命令是一种常见的编程实践. #!/bin/bash # basic for command for test in A B C D E F G H I J K L M N O P Q do echo The next letter is $test done 结果:The next letter is AThe next letter is BThe next letter is CThe next letter is…
许多程序要就对shell脚本中的命令施加一些逻辑控制流程. 结构化命令允许你改变程序执行的顺序.不一定是依次进行的 12.1 使用if-then语句 如下格式: if command then commands fi if语句会允许if后面的那个命令,如果该命令的退出码的0(代表成功了)位于then部分的命令就会被执行.否则不执行. 例子: #!/bin/bash # if then test if pwd then echo "pwd success" fi #…
shell在逻辑流程控制这里会根据设置的变量值的条件或其他命令的结果跳过一些命令或者循环执行的这些命令.这些命令通常称为结构化命令 1.if-then语句介绍 基本格式 if command then commands fi 在其他语言中if语句后的对象值为TRUE或FALSE的等式.bash shell脚本中的if不是这样的 [root@eyu sbin]# sh data.sh 2018年 10月 04日 星期四 18:45:15 CST echo it worked [root@eyu s…