Shell if引數 以及 變數

2021-06-16 05:52:13 字數 2492 閱讀 8045

[ -a file ] 如果 file 存在則為真。

[ -b file ] 如果 file 存在且是乙個塊特殊檔案則為真。

[ -c file ] 如果 file 存在且是乙個字特殊檔案則為真。

[ -d file ] 如果 file 存在且是乙個目錄則為真。

[ -e file ] 如果 file 存在則為真。

[ -f file ] 如果 file 存在且是乙個普通檔案則為真。

[ -g file ] 如果 file 存在且已經設定了sgid則為真。

[ -h file ] 如果 file 存在且是乙個符號連線則為真。

[ -k file ] 如果 file 存在且已經設定了粘制位則為真。

[ -p file ] 如果 file 存在且是乙個名字管道(f如果o)則為真。

[ -r file ] 如果 file 存在且是可讀的則為真。

[ -s file ] 如果 file 存在且大小不為0則為真。

[ -t fd ] 如果檔案描述符 fd 開啟且指向乙個終端則為真。

[ -u file ] 如果 file 存在且設定了suid (set user id)則為真。

[ -w file ] 如果 file 如果 file 存在且是可寫的則為真。

[ -x file ] 如果 file 存在且是可執行的則為真。

[ -o file ] 如果 file 存在且屬有效使用者id則為真。

[ -g file ] 如果 file 存在且屬有效使用者組則為真。

[ -l file ] 如果 file 存在且是乙個符號連線則為真。

[ -n file ] 如果 file 存在 and has been mod如果ied since it was last read則為真。

[ -s file ] 如果 file 存在且是乙個套接字則為真。

[ file1 -nt file2 ] 如果 file1 has been changed more recently than file2, or 如果 file1 exists and file2 does not則為真。

[ file1 -ot file2 ] 如果 file1 比 file2 要老, 或者 file2 存在且 file1 不存在則為真。

[ file1 -ef file2 ] 如果 file1 和 file2 指向相同的裝置和節點號則為真。

[ -o optionname ] 如果 shell選項 「optionname」 開啟則為真。

[ -z string ] 「string」 的長度為零則為真。

[ -n string ] or [ string ] 「string」 的長度為非零 non-zero則為真。

[ string1 == string2 ] 如果2個字串相同。 「=」 may be used instead of 「==」 for strict posix compliance則為真。

[ string1 != string2 ] 如果字串不相等則為真。

[ string1 < string2 ] 如果 「string1」 sorts before 「string2」 lexicographically in the current locale則為真。

[ string1 > string2 ] 如果 「string1」 sorts after 「string2」 lexicographically in the current locale則為真。

[ arg1 op arg2 ] 「op」 is one of -eq, -ne, -lt, -le, -gt or -ge. these arithmetic binary operators return true if 「arg1」 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to 「arg2」, respectively. 「arg1」 and 「arg2」 are integers.

unix shell 裡面比較字元寫法:

-eq   等於

-ne    不等於

-gt    大於

-lt    小於

-le    小於等於

-ge   大於等於

-z    空串

=     兩個字元相等

!=    兩個字元不等

-n    非空串

來自:常用的shell預定義變數:

$# 位置引數的數量。

$* 所有位置引數的內容。

$? 命令執行後返回的狀態。

$$ 當前程序的程序號。

$! 後台執行的最後乙個程序號。

$0 當前執行的程序名。

其中,$?用於檢查上乙個命令執行是否正確。(在linux中,命令退出狀態為0表示該命令正確執行,任何非0值表示命令出錯。)

$$變數最常見的用途是用做暫存檔案的名字以保證暫存檔案不會重複。

animation引數以及用法

它有如下取值 animation name 檢索或設定物件所應用的動畫名稱 animation duration 檢索或設定物件動畫的持續時間 animation timing function 檢索或設定物件動畫的過渡型別 animation delay 檢索或設定物件動畫延遲的時間 animat...

gcc g 引數以及使用

c原始檔到可執行一共需要經歷4個階段。使用gcc編譯程式要經過預處理 編譯 彙編 鏈結。預處理 編譯器主要載入標頭檔案 條件編譯 巨集替換,使用 gcc e main.c main.i,編譯 編譯過程中,編譯器主要做語法檢查和詞法分析,沒有問題之後將會翻譯成彙編 或者中間 gcc s main.i ...

shell中的條件判斷 引數以及變數替換

一 test命令 test命令是shell內部命令,它計算作為其引數的表示式是真還是假。如果表示式為真,則test返回0 注意與c語言0表示false不同 如果表示式為假,返回非0。shell提供了另外乙個呼叫test命令的方式,就是用方括號 來代替單詞test。呼叫test命令的格式為 test ...