Shell脚本中常用的控制结构
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 ] thencommands
elif [ test_command ]
then
commands
...
...
else (optional)
commands
fi
for ... in语句
for 变量 in 变量列表 docommands
done
while语句
while 条件为真 docommands
done
until语句
until 条件为真 docommands
done
case语句
case $variable in match_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
评论暂时关闭