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

shell 函數參數
來源:易賢網 閱讀:848 次 日期:2016-06-16 10:51:12
溫馨提示:易賢網小編為您整理了“shell 函數參數”,方便廣大網友查閱!

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

帶參數的函數示例:

?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 不能獲取第十個參數,獲取第十個參數需要${10}。當n>=10時,需要使用${n}來獲取參數。

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

參數處理 說明

$# 傳遞到腳本的參數個數

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

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

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

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

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

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

更多信息請查看腳本欄目
下一篇:js操作下拉框
易賢網手機網站地址:shell 函數參數
由于各方面情況的不斷調整與變化,易賢網提供的所有考試信息和咨詢回復僅供參考,敬請考生以權威部門公布的正式信息和咨詢為準!

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

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
云南網警備案專用圖標
聯系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網
云南網警報警專用圖標
主站蜘蛛池模板: 泰宁县| 抚顺县| 沙田区| 衡水市| 邵阳县| 依安县| 洛川县| 清涧县| 自贡市| 灵武市| 伊通| 彰武县| 杭锦后旗| 牙克石市| 花莲县| 黔江区| 玉溪市| 双峰县| 保定市| 兰西县| 昭通市| 台江县| 来凤县| 牡丹江市| 二手房| 南陵县| 永丰县| 中阳县| 高唐县| 治县。| 布拖县| 河间市| 青铜峡市| 武宁县| 东阳市| 潮安县| 陆丰市| 防城港市| 台南市| 安康市| 梅州市|