shell 的條件執行

條件測試

1.test命令:

 文件屬性測試

 字符串測試

 算術測試

 語法: test EXPRESSION

 或

 [ EXPRESSION ]

 在bash中還有一個` `,它是[]的提高版本。

 ` EXPRESSION ` 

 [ 10 \> 9]  [[ 10 > 9]]

2. if 的語法結構

 if test-commands; then consequent-commands; fi

 或

 if test-commands; then

  consequent-commands

 fi

 或

 if test-commands

 then

  consequent-commands

 fi

3.if...else...fi

 if []

 then 

 else

 fi

4.if...elif...else...fi

if [];then

 commands

elif [];then

 commands

else

  commands

fi


5.case 語句

case EXPRESSION in

PATTERN1)

    commands;;

PATTERN2)

    commands;;

esac

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章