linux中 中括號 中的判斷引數

2021-04-25 19:42:13 字數 1557 閱讀 2929

源自:http://www.diybl.com/course/6_system/linux/linuxjs/20081117/151774.html

-b file   

若檔案存在且是乙個塊特殊檔案,則為真

-c file             若檔案存在且是乙個字元特殊檔案,則為真

-d file                若檔案存在且是乙個目錄,則為真

-e file                若檔案存在,則為真

-f file                 若檔案存在且是乙個規則檔案,則為真

-g file                若檔案存在且設定了sgid位的值,則為真

-h file                若檔案存在且為乙個符合鏈結,則為真

-k file                   若檔案存在且設定了"sticky"位的值

-p file                   若檔案存在且為一已命名管道,則為真

-r file                    若檔案存在且可讀,則為真

-s file                   若檔案存在且其大小大於零,則為真

-u file                   若檔案存在且設定了suid位,則為真

-w file               若檔案存在且可寫,則為真

-x file                   若檔案存在且可執行,則為真

-o file                   若檔案存在且被有效使用者id所擁有,則為真

-z string  

若string長度為0,則為真

-n string                             若string長度不為0,則為真

string1 = string2      若兩個字串相等,則為真

string1 != string2      若兩個字串不相等,則為真

int1 -eq int2      

若int1等於int2,則為真

int1 -ne int2                   若int1不等於int2,則為真

int1 -lt int2                  若int1小於int2,則為真

int1 -le int2                    若int1小於等於int2,則為真

int1 -gt int2                    若int1大於int2,則為真

int1 -ge int2         若int1大於等於int2,則為真

!expr           

若expr為假則復合表示式為真。expr可以是任何有效的測試表示式

expr1 -a expr2        若expr1和expr2都為真則整式為真

expr1 -o expr2        若expr1和expr2有乙個為真則整式為真

源自:http://www.cppblog.com/prayer/archive/2008/08/12/58662.html

Shell 指令碼中中括號「 」判斷問題

在用 測試的時候,由於不知道什麼原因,判斷的結果總為真。例如 choice n o choice n echo e oh interrupt exit 0無論變數 choice 是什麼內容,測試總為然後輸出後面的內容。然後查閱資料,發現原因。在bash的語法中使用中括號作為shell的判斷式時,中括...

PHP json中的大括號和中括號

當array是乙個從0開始的連續陣列時,json encode出來的結果是乙個由括起來的字串。而當array是不從0開始或者不連續的陣列時,json encode出來的結果是乙個由 括起來的key value模式的字串。當字串為 1,1,1 這種模式時,json decode預設解析出來的結果是乙個...

shell中 if 判斷條件的引數

1 檔案判斷 a file 如果 file 存在則為真。b file 如果 file 存在且是乙個塊特殊檔案則為真。c file 如果 file 存在且是乙個字特殊檔案則為真。d file 如果 file 存在且是乙個目錄則為真。e file 如果 file 存在則為真。f file 如果 file...