shell 命令引數

2022-04-18 18:33:15 字數 2127 閱讀 7253

$# 是傳給指令碼的引數個數

$0 是指令碼本身的名字

$1 是傳遞給該shell指令碼的第乙個引數

$2 是傳遞給該shell指令碼的第二個引數

$@ 是傳給指令碼的所有引數的列表

$* 是以乙個單字串顯示所有向指令碼傳遞的引數,與位置變數不同,引數可超過9個

$$ 是指令碼執行的當前程序id號

$? 是顯示最後命令的退出狀態,0表示沒有錯誤,其他表示有錯誤

-eq //等於

-ne //不等於

-gt //大於

-lt //小於

ge //大於等於

le //小於等於

[ -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 存在且大小不為o則為真。

[ -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則為真。

Del命令引數 vb呼叫shell

dos下的del命令是用來刪除檔案的,而dos下的rd命令才是用來刪除資料夾的,命令的具體使用方法請看下面的文字 del 命令 刪除乙個或數個檔案。del p f s q a attributes names erase p f s q a attributes names names 指定乙個或數...

Shell的命令列引數

當你執行shell指令碼時,如 myshell.sh a b c d e f 其中,後部分的a b c d e f 是傳入shell指令碼myshell.sh的引數 在shell指令碼裡,我們可以通過這樣獲得傳入的引數 echo first arg is 1 echo tenth arg is 其中...

Del命令引數 vb呼叫shell

dos下的del命令是用來刪除檔案的,而dos下的rd命令才是用來刪除資料夾的,命令的具體使用方法請看下面的文字 del 命令 刪除乙個或數個檔案。del p f s q a attributes names erase p f s q a attributes names names 指定乙個或數...