2019-04-02 15:34:19 2959瀏覽
今天小編給讀者們分享一下shell中常見參數(shù)及判斷命令,對Linux開發(fā)技術感興趣或者是想要參加Linux培訓進入Linux開發(fā)領域中的小伙伴可以隨小編來看一下,文中有詳細的代碼列出,具有很好的參考價值,希望對讀者們有所幫助。
Shell常用特殊變量:
經(jīng)常會在shell命令中,看到$0, $#, $*, $@, $?, $$這樣的取值,這些代表什么呢?
$* 和 $@ 都是將參數(shù)一個一個返回
"$*"將所有參數(shù)當做一個整體字符串返回 , "$@"將參數(shù)一個一個返回
常用判斷參數(shù)
在shell命令文件中還經(jīng)常會看到類似與if [ -z "${SPARK_HOME}" ]; then這樣的判斷語句?是不是也和我一樣很疑惑-z是什么含義?
下面是幾個常見的參數(shù),供查詢使用:
-a file exists. -b file exists and is a block special file. -c file exists and is a character special file. -d file exists and is a directory. -e file exists (just the same as -a). -f file exists and is a regular file. -g file exists and has its setgid(2) bit set. -G file exists and has the same group ID as this process. -k file exists and has its sticky bit set. -L file exists and is a symbolic link. -n string length is not zero. -o Named option is set on. -O file exists and is owned by the user ID of this process. -p file exists and is a first in, first out (FIFO) special file or named pipe. -r file exists and is readable by the current process. -s file exists and has a size greater than zero. -S file exists and is a socket. -t file descriptor number fildes is open and associated with a terminal device. -u file exists and has its setuid(2) bit set. -w file exists and is writable by the current process. -x file exists and is executable by the current process. -z string length is zero.
判斷命令
shell中除了有上邊這樣用來判斷文件是否存在的參數(shù),當然還有判斷兩個數(shù)是否相等這樣更常規(guī)的命令。
例如,if [ $# -gt 0 ]這樣判斷傳入?yún)?shù)個數(shù)是否為0
以上就是扣丁學堂Linux在線學習小編給大家分享的shell中常見參數(shù)及判斷命令,希望對小伙伴們有所幫助,想要了解更多內容的小伙伴可以登錄扣丁學堂官網(wǎng)咨詢。
想要學好Linux開發(fā)小編給大家推薦口碑良好的扣丁學堂,扣丁學堂有專業(yè)老師制定的Linux學習路線圖輔助學員學習,此外還有與時俱進的Linux課程體系和Linux視頻教程供大家學習,想要學好Linux開發(fā)技術的小伙伴快快行動吧。扣丁學堂Linux技術交流群:422345477。
【關注微信公眾號獲取更多學習資料】 【掃碼進入HTML5進階免費公開課】