1. 程式人生 > >linux shell程式設計 二

linux shell程式設計 二

條件選擇 if -then  語句

if command
then
    commands
fi
另一種形式
if command; then
    commands
fi

關於退出狀態碼,你只需要記住:正常退出(命令執行正常)的狀態碼是0, 非正常退出的狀態碼不是0(有不少)。

以上語句的語義為: 如果if後面的命令執行正常(狀態碼0),那麼就執行then後面的語句。否則不執行。 fi代表if語句的結束

 if ——then -else語句

if command
then
    commands
else
    commands
fi

2.test命令用於判斷條件是否成立  數值比較,,字元創比較,檔案比較