好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

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

在Linux的系統Shell腳本中使用if語句的方法

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

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

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 條件為真,執行 if 語句里的代碼塊,如果 if 條件為假,執行 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 條件為假時執行。我們還可以將 if 語句嵌套到一起,來實現多重條件的檢測。我們可以使用 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

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

巨人網絡通訊聲明:本文標題《在Linux的系統Shell腳本中使用if語句的方法》,本文關鍵詞  在,Linux,的,系統,Shell,腳本,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《在Linux的系統Shell腳本中使用if語句的方法》相關的同類信息!
  • 本頁收集關于在Linux的系統Shell腳本中使用if語句的方法的相關信息資訊供網民參考!
  • 推薦文章