婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > 在Linux的系統(tǒng)Shell腳本中使用if語(yǔ)句的方法

在Linux的系統(tǒng)Shell腳本中使用if語(yǔ)句的方法

熱門(mén)標(biāo)簽:鄭州營(yíng)銷(xiāo)外呼系統(tǒng)運(yùn)營(yíng)商 百度地圖標(biāo)注陰影動(dòng)態(tài) 鹽城客服外呼系統(tǒng)軟件 貴陽(yáng)語(yǔ)音電銷(xiāo)機(jī)器人招商 北京市地圖標(biāo)注 廳外呼梯系統(tǒng)布線 焦作人工智能電話機(jī)器人軟件 淘寶系統(tǒng)退貨外呼項(xiàng)目考試答案 2020電銷(xiāo)機(jī)器人排行

Bourne Shell 的 if 語(yǔ)句和大部分編程語(yǔ)言一樣 - 檢測(cè)條件是否真實(shí),如果條件為真,shell 會(huì)執(zhí)行這個(gè) if 語(yǔ)句指定的代碼塊,如果條件為假,shell 就會(huì)跳過(guò) if 代碼塊,繼續(xù)執(zhí)行之后的代碼。

if 語(yǔ)句的語(yǔ)法:

   

復(fù)制代碼
代碼如下:
if [ 判斷條件 ]
then
command1
command2
……..
last_command
fi/p> p>Example:/p> p> #!/bin/bash
number=150
if [ $number -eq 150 ]
then
echo "Number is 150"
fi

if-else 語(yǔ)句:

除了標(biāo)準(zhǔn)的 if 語(yǔ)句之外,我們還可以加入 else 代碼塊來(lái)擴(kuò)展 if 語(yǔ)句。這么做的主要目的是:如果 if 條件為真,執(zhí)行 if 語(yǔ)句里的代碼塊,如果 if 條件為假,執(zhí)行 else 語(yǔ)句里的代碼塊。
語(yǔ)法:

   

復(fù)制代碼
代碼如下:
if [ 判斷條件 ]
then
command1
command2
……..
last_command
else
command1
command2
……..
last_command
fi

Example:

   

復(fù)制代碼
代碼如下:
#!/bin/bash
number=150
if [ $number -gt 250 ]
then
echo "Number is greater"
else
echo "Number is smaller"
fi

If..elif..else..fi 語(yǔ)句 (簡(jiǎn)寫(xiě)的 else if)

Bourne Shell 的 if 語(yǔ)句語(yǔ)法中,else 語(yǔ)句里的代碼塊會(huì)在 if 條件為假時(shí)執(zhí)行。我們還可以將 if 語(yǔ)句嵌套到一起,來(lái)實(shí)現(xiàn)多重條件的檢測(cè)。我們可以使用 elif 語(yǔ)句(else if 的縮寫(xiě))來(lái)構(gòu)建多重條件的檢測(cè)。
語(yǔ)法 :

   

復(fù)制代碼
代碼如下:
if [ 判斷條件1 ]
then
command1
command2
……..
last_command
elif [ 判斷條件2 ]
then
command1
command2
……..
last_command
else
command1
command2
……..
last_command
fi

Example :

   

復(fù)制代碼
代碼如下:
#!/bin/bash
number=150
if [ $number -gt 300 ]
then
echo "Number is greater"
elif [ $number -lt 300 ]
then
echo "Number is Smaller"
else
echo "Number is equal to actual value"
fi

多重 if 語(yǔ)句 :

If 和 else 語(yǔ)句可以在一個(gè) bash 腳本里相互嵌套。關(guān)鍵詞 “fi” 表示里層 if 語(yǔ)句的結(jié)束,所有 if 語(yǔ)句必須使用 關(guān)鍵詞 “fi” 來(lái)結(jié)束。

基本 if 語(yǔ)句的嵌套語(yǔ)法:

   

復(fù)制代碼
代碼如下:
if [ 判斷條件1 ]
then
command1
command2
……..
last_command
else
if [ 判斷條件2 ]
then
command1
command2
……..
last_command
else
command1
command2
……..
last_command
fi
fi

Example:

   

復(fù)制代碼
代碼如下:
#!/bin/bash
number=150
if [ $number -eq 150 ]
then
echo "Number is 150"
else
if [ $number -gt 150 ]
then
echo "Number is greater"
else
echo "'Number is smaller"
fi
fi

標(biāo)簽:遼寧 樂(lè)山 大理 大慶 青島 周口 六安 大興安嶺

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《在Linux的系統(tǒng)Shell腳本中使用if語(yǔ)句的方法》,本文關(guān)鍵詞  在,Linux,的,系統(tǒng),Shell,腳本,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《在Linux的系統(tǒng)Shell腳本中使用if語(yǔ)句的方法》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于在Linux的系統(tǒng)Shell腳本中使用if語(yǔ)句的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 汤阴县| 临海市| 青铜峡市| 兴义市| 海丰县| 益阳市| 保康县| 千阳县| 桓台县| 华池县| 高淳县| 叙永县| 涡阳县| 城步| 牙克石市| 龙川县| 比如县| 绥棱县| 长汀县| 阿拉尔市| 延寿县| 华阴市| 巨鹿县| 中牟县| 文山县| 建湖县| 高淳县| 晋州市| 冷水江市| 崇信县| 新兴县| 洮南市| 乌什县| 尉氏县| 泰安市| 永顺县| 金门县| 车致| 蓬莱市| 兴宁市| 阿鲁科尔沁旗|