濮阳杆衣贸易有限公司

主頁 > 知識庫 > 對shell中常見參數(shù)及判斷命令介紹

對shell中常見參數(shù)及判斷命令介紹

熱門標簽:輝縣市地圖標注 同花順電話機器人微信 武漢語音電銷機器人加盟 北京電銷機器人對市場的影響 房產證地圖標注的兩個面積 外呼系統(tǒng)的合法性 威海電銷外呼系統(tǒng)好用嗎 地圖標注x是啥意思 湖北孝感如何辦理

Shell常用特殊變量

經常會在shell命令中,看到$0, $#, $*, $@, $?, $$這樣的取值,這些代表什么呢?

變量 含義
$0 當前腳本的文件名
$n 傳遞給腳本或函數(shù)的參數(shù)。n 是一個數(shù)字,表示第幾個參數(shù)。例如,第一個參數(shù)是$1,第二個參數(shù)是$2
$# 傳遞給腳本或函數(shù)的參數(shù)個數(shù)
$* 傳遞給腳本或函數(shù)的所有參數(shù)
$@ 傳遞給腳本或函數(shù)的所有參數(shù)。被雙引號(” “)包含時,與 $* 稍有不同
$? 上個命令的退出狀態(tài),或函數(shù)的返回值。成功返回0,失敗返回1
$$ 當前Shell進程ID。對于 Shell 腳本,就是這些腳本所在的進程ID

$* 和 $@ 都是將參數(shù)一個一個返回

"$*"將所有參數(shù)當做一個整體字符串返回 , "$@"將參數(shù)一個一個返回

常用判斷參數(shù)

在shell命令文件中還經常會看到類似與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 ]這樣判斷傳入參數(shù)個數(shù)是否為0

命令 含義
-eq 等于
-ne 不等于
-gt 大于
-lt 小于
ge 大于等于
le 小于等于

以上這篇對shell中常見參數(shù)及判斷命令介紹就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PowerShell函數(shù)中接收管道參數(shù)實例
  • Shell腳本用for循環(huán)遍歷參數(shù)的方法技巧
  • 一條命令讓你明白shell中read命令的常用參數(shù)
  • shell 使用數(shù)組作為函數(shù)參數(shù)的方法(詳解)
  • Shell腳本傳遞參數(shù)的3種方法比較
  • shell腳本使用兩個橫杠接收外部參數(shù)的方法

標簽:麗江 安康 迪慶 日喀則 西寧 蚌埠 武威 紹興

巨人網絡通訊聲明:本文標題《對shell中常見參數(shù)及判斷命令介紹》,本文關鍵詞  對,shell,中,常見,參數(shù),及,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《對shell中常見參數(shù)及判斷命令介紹》相關的同類信息!
  • 本頁收集關于對shell中常見參數(shù)及判斷命令介紹的相關信息資訊供網民參考!
  • 推薦文章
    临城县| 宁都县| 会东县| 承德市| 手游| 收藏| 富源县| 思南县| 玉门市| 丰原市| 晋江市| 汉沽区| 来安县| 普兰县| 东台市| 名山县| 鲜城| 曲沃县| 恩平市| 泾源县| 南宫市| 鹿泉市| 鲜城| 青河县| 乐安县| 绍兴市| 达拉特旗| 新巴尔虎左旗| 渝中区| 潢川县| 云梦县| 平泉县| 东平县| 金坛市| 石渠县| 赞皇县| 阳新县| 托克逊县| 方山县| 垦利县| 安义县|