Shell流程控制
2016-03-21 22:38
471 查看
Shell 流程控制
Shell 流程控制判断
if-elif-else-fi
逻辑与
test 命令
case
循环
for
while
until
break与continue
判断
if-elif-else-fi
if condition [ condition ... ] then statements-if-true-1 [ elif condition [ condition ...] then statements-if-true-2 ...] [ else statements-if-all-else-fails ] fi
注: 方括号中的内容非必须。
逻辑!、&&与||
if ! condition then : #冒号类似空操作 else statements fi
if cond1 && cond2 then statements fi
if cond1 || cond2 then statements fi
注: 以上逻辑操作支持短路功能。
test 命令
一般使用test的退出状态,其等效[ … ]。case
case $var in cond1) .... ;; #本选项结束 cond2) .... ;; *) .... #不需要;; esac
循环
for
for i in list do statements done >
注: list省略则表示遍历整个命令行参数
while
while cond do statements done
until
until cond do statements done
**注:**until后面cond未成功退出,则循环继续。
break与continue
break 与 continue控制循环的流程,类似于C语言,比起C语言,shell提供多层结束和多层跳出。break num continue num
参考:
1、Shell脚本学习指南。
相关文章推荐
- android wifi 无线调试
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- Linux Shell常用技巧
- Shell 脚本编程陷阱
- Ruby基础知识之基本流程控制
- shell字符串操作详解
- Lua中的控制结构(流程控制)简明总结
- Shell中删除某些文件外所有文件的3个方法
- Ruby中执行Linux shell命令的六种方法详解
- Lua基础教程之赋值语句、表达式、流程控制、函数学习笔记
- VB使用shell函数打开外部exe程序的实现方法
- Shell编程的一些知识集合
- Shell中的for和while循环详细总结
- 什么是Shell?Shell脚本基础知识详细介绍
- Shell脚本中引用、调用另一个脚本文件的2种方法
- Shell脚本解压rpm软件包
- Linux Shell 数组建立及使用技巧
- ruby 流程控制 方法