1,每隔3秒,打印一次系统负载 #!/bin/bash while true do uptime done 2,把监控结果保存到文件,在后台执行,然后用tail -f监控文件变化 ghostwu@dev:~/linux/shell/flow_control$ sh while.sh & [] #!/bin/bash while true do uptime >> log.txt done ghostwu@dev:~/linux/shell/flow_control$ tail -f l
Linux Shell for循环结构 循环结构 1:循环开始条件 2:循环操作 3:循环终止的条件 shell语言 for,while,util for循环 语法: (1) for 变量 in 取值列表:do statement statement done (2) for 变量 in 取值列表 do statement statement done 上面两个用法的效果是一样的. 取值列表:
for循环 for 循环是固定循环,也就是在循环时已经知道需要进行几次循环.有时也把 for 循环称为计数循环.语法: for 变量 in 值1 值2 值3… do 程序 done 在这种语法中,for 循环的次数取决于 in 后面值的个数(以空格分隔),有几个值就循环几次,并且每次循环都把值赋予变量.也就是说,假设 in 后面有三个值,for 会循环三次,第一次循环会把值 1 赋予变量,第二次循环会把值 2 赋予变量,以此类推. 示例:打印时间. [root@localhost ~]# vi
详细介绍Linux shell脚本基础学习(五) Linux shell脚本基础前面我们在介绍Linux shell脚本的控制流程时,还有一部分内容没讲就是有关here document的内容这里继续. Linux shell脚本基础已经被分成好几个部分了,这里对控制流程的内容也就马上讲完了,这是最后一部分关于here document,这里举例稍微有点复杂,我们慢慢来分析这个复杂Linux shell脚本. 6. Here documents 当要将几行文字传递给一个命令时,here docu
There are two types of bash for loops available. One using the “in” keyword with list of values, another using the C programming like syntax. This article is part of our on-going bash tutorial series. This explains both of the bash for lo
原文链接:http://www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case).下面我将通过例子介绍下,各个语句使用方法. 一.shell条件语句(if用法) if语句结构[if/then/elif/else/fi] if 条件测试语句 then action [elif 条件 action else action
1.for循环语句实例1.1 最基本的for循环 #!/bin/bash for x in one two three four do echo number $x done 注:"for" 循环总是接收 "in" 语句之后的某种类型的字列表.在本例中,指定了四个英语单词,但是字列表也可以引用磁盘上的文件,甚至文件通配符.实例1.2 #!/bin/bash for x in /var/log/* do #echo "$x is a file
本文是Linux Shell系列教程的第(十一)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上一篇Linux Shell系列教程之(十)Shell for循环中,我们已经对Shell 循环语句的for循环进行了介绍,本篇给大家介绍下Shell 中另一种循环语句:Shell while循环. Shell while循环语法及特点 Shell while循环的语法如下所示: while command do Statement(s) to be executed if
@代表所有参数所以如果后面跟上echo $v你会发现他会一次显示user userdebug eng $poo -le ${#prodlist[@]} 这句话是说 $poo小于等于prodlist中的所有的值是这个意思吗? 1.Shell for循环语法 for 变量 in 列表do command1 command2 ... commandNdone **也可以写成:for var in list; do - 13.1.1.读取列表中的值#!/bin/bash#basic for comman
Linux Shell高级技巧(一) http://www.cnblogs.com/stephen-liu74/archive/2011/12/22/2271167.html一.将输入信息转换为大写字符后再进行条件判断二.为调试信息设置输出级别三.判断参数是否为数字四.判断整数变量的奇偶性五.将Shell命令赋值给指定变量,以保证脚本的移植性六.获取当前时间距纪元时间(1970年1月1日)所经过的天数 Linux Shell高级技巧(二) http://www.cnblogs.com/steph