Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真”: 退出条件:当CONDITION为“假”: while CONDITION; do 循环体 控制变量的修正表达式 done 示例:求100以内所有正整数之和; #!/bin/bash # declare -i sum=0 declare -i i=1 while [ $i -le 100 ]; d
一.我们先看看编写的shell脚本的内容,该shell的作用主要是实现监控某个程序崩溃之后就自动重启该进程. while true do procnum=` ps -ef|grep "test"|grep -v grep|wc -l` if [ $procnum -eq 0 ]; then /home/test& fi sleep 30 done -eq意思是等于0,用于判断该test是否还在运行状态.监控/home/test这个程序是否运行. 二.由于该程序是window上的
写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do myfun count=$[ $count +1 ] done echo "This is the end of the loop" myfun ech