標籤:
test命令用法。功能:檢查檔案和比較值 1)判斷運算式if test (運算式為真)if test !運算式為假test 運算式1 –a 運算式2 兩個運算式都為真test 運算式1 –o 運算式2 兩個運算式有一個為真 2)判斷字串test –n 字串 字串的長度非零test –z 字串 字串的長度為零test 字串1=字串2 字串相等test 字串1!=字串2 字串不等 3)判斷整數test 整數1 –eq 整數2 整數相等test 整數1 –ge 整數2 整數1大於等於整數2test 整數1 –gt 整數2 整數1大於整數2test 整數1 –le 整數2 整數1小於等於整數2test 整數1 –lt 整數2 整數1小於整數2test 整數1 –ne 整數2 整數1不等於整數2 4)判斷檔案test File1 –ef File2 兩個檔案具有同樣的裝置號和i結點號test File1 –nt File2 檔案1比檔案2 新test File1 –ot File2 檔案1比檔案2 舊test –b File 檔案存在並且是塊裝置檔案test –c File 檔案存在並且是字元裝置檔案test –d File 檔案存在並且是目錄test –e File 檔案存在test –f File 檔案存在並且是正規檔案test –g File 檔案存在並且是設定了組IDtest –G File 檔案存在並且屬於有效組IDtest –h File 檔案存在並且是一個符號連結(同-L)test –k File 檔案存在並且設定了sticky位test –b File 檔案存在並且是塊裝置檔案test –L File 檔案存在並且是一個符號連結(同-h)test –o File 檔案存在並且屬於有效使用者IDtest –p File 檔案存在並且是一個具名管道test –r File 檔案存在並且可讀test –s File 檔案存在並且是一個通訊端test –t FD 檔案描述符是在一個終端開啟的test –u File 檔案存在並且設定了它的set-user-id位test –w File 檔案存在並且可寫test –x File 檔案存在並且可執行
Shell文法中的test命令用法