歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Shell腳本中常用的控制結構

Shell腳本中常用的控制結構

日期:2017/3/1 10:29:35   编辑: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 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

Copyright © Linux教程網 All Rights Reserved