1. 程式人生 > >shell條件判斷二 (if、case)

shell條件判斷二 (if、case)

單分支if

  1. 格式
    (1)if [];then
    fi
    (2)if []
    then
    fi
  2. 這裡寫圖片描述
  3. 應用:(1)判斷使用者是誰(2)判斷分割槽使用率

雙分支if

  1. 格式: if []
    then
    else
    fi
  2. 應用:(1)判斷是否是目錄(2)判斷apache是否啟動(3)加入任務計劃
    這裡寫圖片描述
  3. ps aux顯示系統進行

多分支if

  1. exit 1
  2. 應用:判斷使用者輸入的是什麼檔案

case語句


  1. 這裡寫圖片描述