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

主頁 > 知識庫 > 在Linux的系統(tǒng)Shell腳本中使用if語句的方法

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

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

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

if 語句的語法:

   

復制代碼
代碼如下:
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 語句:

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

   

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

Example:

   

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

If..elif..else..fi 語句 (簡寫的 else if)

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

   

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

Example :

   

復制代碼
代碼如下:
#!/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 語句 :

If 和 else 語句可以在一個 bash 腳本里相互嵌套。關鍵詞 “fi” 表示里層 if 語句的結束,所有 if 語句必須使用 關鍵詞 “fi” 來結束。

基本 if 語句的嵌套語法:

   

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

Example:

   

復制代碼
代碼如下:
#!/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

標簽:遼寧 樂山 大理 大慶 青島 周口 六安 大興安嶺

巨人網(wǎng)絡通訊聲明:本文標題《在Linux的系統(tǒng)Shell腳本中使用if語句的方法》,本文關鍵詞  在,Linux,的,系統(tǒng),Shell,腳本,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《在Linux的系統(tǒng)Shell腳本中使用if語句的方法》相關的同類信息!
  • 本頁收集關于在Linux的系統(tǒng)Shell腳本中使用if語句的方法的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 广河县| 江都市| 彝良县| 迭部县| 东城区| 绥江县| 墨玉县| 南召县| 尖扎县| 万全县| 河津市| 西贡区| 图木舒克市| 中牟县| 平山县| 建始县| 湘潭县| 平顺县| 安康市| 静乐县| 沁阳市| 基隆市| 莲花县| 宝应县| 平度市| 南充市| 白沙| 蓝田县| 古交市| 泾川县| 阿尔山市| 通道| 乐亭县| 兴业县| 巴彦淖尔市| 治县。| 新余市| 丹阳市| 新乡市| 广东省| 曲麻莱县|