1)判斷表達式

if test  (表達式為真)

if test !表達式為假

test 表達式1 –a 表達式2                  兩個表達式都為真

test 表達式1 –o 表達式2                 兩個表達式有一個為真

test 表達式1 !  表達式2                    條件求反

2)判斷字符串

test –n 字符串                                   字符串的長度非零

test –z 字符串                                    字符串的長度是否為零

test 字符串1=字符串2                    字符串是否相等,若相等返回true

test 字符串1!=字符串2               字符串是否不等 ,若不等反悔false

3)判斷整數

test 整數1 –eq 整數2                        整數相等

test 整數1 –ge 整數2                        整數1大於等於整數2

test 整數1 –gt 整數2                         整數1大於整數2

test 整數1 –le 整數2                         整數1小於等於整數2

test 整數1 –lt 整數2                          整數1小於整數2

test 整數1 –ne 整數2                        整數1不等於整數2

4)判斷文件

test  File1 –ef  File2                           兩個文件是否為同一個文件,可用於硬連接。主要判斷兩個文件是否指向同一個inode。

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                                           文件是否是設置了組ID

test –G File                                           文件屬於的有效組ID

test –h File                                           文件是否是一個符號鏈接(同-L)

test –k File                                           文件是否設置了Sticky bit位

test –b File                                           文件存在並且是塊設備文件

test –L File                                           文件是否是一個符號鏈接(同-h)

test –o File                                           文件的屬於有效用戶ID

test –p File                                           文件是一個命名管道

test –r File                                            文件是否可讀

test –s File                                           文件是否是非空白文件

test –t FD                                             文件描述符是在一個終端打開的

test –u File                                           文件存在並且設置了它的set-user-id位

test –w File                                          文件是否存在並可寫

test –x File                                           文件屬否存在並可執行

arrow
arrow
    全站熱搜

    主要步驟 發表在 痞客邦 留言(0) 人氣()