shell脚本之for语句
来源:互联网 发布:股市大数据分析工具 编辑:程序博客网 时间:2024/05/21 10:01
for: 传统 shell 格式
原来的 for 命令语法是:
for variable [in words]; do commandsdone
for i in A B C D;do
echo $i;
done
echo $i;
done
$ for i in {A..D}; do echo $i; done
for: C 语言格式
最新版本的 bash 已经添加了第二种格式的 for 命令语法,该语法相似于 C 语言中的 for 语法格式。 其它许多编程语言也支持这种格式:
for (( expression1; expression2; expression3 )); do commandsdone
这里的 expression1,expression2,和 expression3 都是算术表达式,commands 是每次循环迭代时要执行的命令。 在行为方面,这相当于以下构造形式:
(( expression1 ))while (( expression2 )); do commands (( expression3 ))done
expression1 用来初始化循环条件,expression2 用来决定循环结束的时间,还有在每次循环迭代的末尾会执行 expression3。
这里是一个典型应用:
#!/bin/bash# simple_counter : demo of C style for commandfor (( i=0; i<5; i=i+1 )); do echo $idone
脚本执行之后,产生如下输出:
[me@linuxbox ~]$ simple_counter01234
0 0
- shell脚本之for语句
- shell脚本:for语句
- shell脚本编程之for语句、if语句使用介绍
- shell 脚本之for
- shell脚本之if语句
- shell脚本之case语句
- shell脚本之-if流程控制语句和for循环语句的使用
- shell 脚本之 for 循环
- Linux-shell脚本-for语句/where语句/until语句
- shell 学习之for语句
- Shell 脚本之循环语句(for,while,until)以及case,select,break,continue实例详解
- Shell脚本学习之控制语句
- shell 脚本编程之条件语句
- shell 脚本编程之循环语句
- shell脚本编程之循环语句
- linux shell 脚本 之for 循环
- shell 脚本之for while until循环
- linux shell 编程之for 语句
- weblogic 和 tomcat 的区别利弊,摘自网友
- 如何用AltiumDesigner绘制STC89C51单片机原理图
- 安装office的ISO版本,虚拟光驱
- 初学二叉树
- 文章标题
- shell脚本之for语句
- Apache Cordova 安卓android上传图片或者文件 调用后台服务实现java代码 ft.upload(imageURI, uri, that.uploadSuccess, that.
- CCF 201409-1
- dagger2使用详解
- 安装tokudb报错
- 指针总结
- 新特性:Andorid-foreground 解析
- PAT-B 1035. 插入与归并(25)
- poj2823 Sliding Window