控制流结构
一. 退出状态
1. $ echo $? 最后命令退出状态
2. $$ || 控制次序命令
3. exit n 退出当前进程
4.
二.if 语句
if condition
if condition
then
command1 if condition is true or if exit status
of condition is 0 (zero)
...
...
fi
if...else...fi
If given condition is true then command1 is executed otherwise command2 is executed.
Syntax:if condition then condition is zero (true - 0) execute all commands up to else statement else if condition is not true then execute all commands up to fi fiif-then-else
Syntax:if condition then condition is zero (true - 0) execute all commands up to elif statement elif condition1
then condition1 is zero (true - 0) execute all commands up to elif statement elif condition2 then condition2 is zero (true - 0) execute all commands up to elif statement else None of the above condtion,condtion1,condtion2 are true (i.e. all of the above nonzero or false) execute all commands up to fi fi
if 条件
then 命令
fi
三.
1.变量值测试
2.Gerp输出检查
3.用变量检查grep输出
4.文件拷贝输出检查
5.当前目录测试
6.文件权限测试:用if语句测试文件权限
7.测试传递到脚本中的参数
$# 表示调用参数的个数
四.Case语句
Case 值 in
模式1}
命令1
…
;;
模式2}
命令2
…
;;
Esac
五.for
1.对for循环使用参数
在for循环中省去in列表,它将接受命令行位置参数作为参数
for params in “$@” 或 for params in “$*”
2. for循环嵌套使用
for 变量名1 in 列表1
do
for 变量名2 in 列表2
do 命令1
done
done
六.Until
Until 循环执行一系列命令直到条件为真时停止
格式
Until 条件
命令1
done
七.While 循环
while 命令
do
命令1
命令2
done