中文字幕免费精品_亚洲视频自拍_亚洲综合国产激情另类一区_色综合咪咪久久

Shell 函數(shù)參數(shù)
來源:易賢網 閱讀:1940 次 日期:2014-09-25 11:55:59
溫馨提示:易賢網小編為您整理了“Shell 函數(shù)參數(shù)”,方便廣大網友查閱!

在shell中,調用函數(shù)時可以向其傳遞參數(shù)。在函數(shù)體內部,通過 $n 的形式來獲取參數(shù)的值,例如,$1表示第一個參數(shù),$2表示第二個參數(shù)...

帶參數(shù)的函數(shù)示例:

?1234567891011 #!/bin/bash funWithParam(){ echo "The value of the first parameter is $1 !" echo "The value of the second parameter is $2 !" echo "The value of the tenth parameter is $10 !" echo "The value of the tenth parameter is ${10} !" echo "The value of the eleventh parameter is ${11} !" echo "The amount of the parameters is $# !" echo "The string of the parameters is $* !"} funWithParam 1 2 3 4 5 6 7 8 9 34 73

輸出:

The value of the first parameter is 1 !

The value of the second parameter is 2 !

The value of the tenth parameter is 10 !

The value of the tenth parameter is 34 !

The value of the eleventh parameter is 73 !

The amount of the parameters is 12 !

The string of the parameters is 1 2 3 4 5 6 7 8 9 34 73 !"

注意,$10 不能獲取第十個參數(shù),獲取第十個參數(shù)需要${10}。當n>=10時,需要使用${n}來獲取參數(shù)。

另外,還有幾個特殊字符用來處理參數(shù):

參數(shù)處理 說明

$# 傳遞到腳本的參數(shù)個數(shù)

$* 以一個單字符串顯示所有向腳本傳遞的參數(shù)

$$ 腳本運行的當前進程ID號

$! 后臺運行的最后一個進程的ID號

$@ 與$#相同,但是使用時加引號,并在引號中返回每個參數(shù)。

$- 顯示Shell使用的當前選項,與set命令功能相同。

$? 顯示最后命令的退出狀態(tài)。0表示沒有錯誤,其他任何值表明有錯誤。

更多信息請查看IT技術專欄

更多信息請查看腳本欄目
易賢網手機網站地址:Shell 函數(shù)參數(shù)

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網
主站蜘蛛池模板: 衡东县| 铁岭县| 双桥区| 安多县| 沂水县| 上饶县| 桐柏县| 海林市| 江西省| 沧源| 长顺县| 延庆县| 永昌县| 久治县| 关岭| 永新县| 林口县| 渭南市| 萨嘎县| 姜堰市| 泰安市| 白朗县| 南皮县| 无棣县| 宁明县| 白银市| 乾安县| 元氏县| 全州县| 汤阴县| 洪湖市| 镇安县| 柳州市| 武平县| 天等县| 于都县| 永登县| 平利县| 武功县| 建宁县| 海伦市|