Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Shell脚本中常用的控制结构

if ... then语句

if [ test_command ]then
commands
fi

if ... then ... else语句

if [ test_command ]then
commands
else
commands
fi

if ... then ... elif ... (else)语句

if [ test_command ]then
commands
elif [ test_command ]then
commands
......else  (optional)
commands
fi

for ... in语句

for 变量 in 变量列表do
commands
done

while语句

while 条件为真do
commands
done

until语句

until 条件为真do
commands
done

case语句

case $variable inmatch_1)
commands_to_execute_for_1;;
match_2)
commands_to_execute_for_2;;
match_3)
commands_to_execute_for_3;;
......*)  (可选 - any other value)commands_to_execute_for_no_match
;;
esac