Shell语句结构总结

1.if语句结构总结
if-then语句格式:
if command
then
commands
fi
if-then-else语句格式:
if command
then
commands
else
commands
fi
嵌套if:
if command
then
commands
elif command2
then
more commands
fi
if-then的高级特性:
a.用于数学表达式的双括号 :(( expression ))
b.用于高级字符串处理功能的双方括号:[[ expression ]]
2.case命令
case variable in
pattern1 | pattern2) commands;;
pattern3) commands2;;
*) default commands;;
esac
3.for命令
for var in list
do
commands
done
4.while命令(返回值状态码为0执行)
while test command
do
othre commands
done
5.until命令(返回值状态码非0执行)
until test command
do
other commands
done
6.控制循环
a.break
b.continue

发表评论

邮箱地址不会被公开。 必填项已用*标注