国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Shell 函數參數

2019-10-26 18:42:42
字體:
來源:轉載
供稿:網友

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

帶參數的函數示例:

#!/bin/bashfunWithParam(){  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表示沒有錯誤,其他任何值表明有錯誤。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永胜县| 聊城市| 江川县| 宜兴市| 陇西县| 隆林| 襄汾县| 宁夏| 精河县| 昌江| 乌拉特后旗| 隆尧县| 平武县| 太保市| 朝阳县| 德安县| 吴江市| 金寨县| 巴彦淖尔市| 绥棱县| 东兴市| 连平县| 聂荣县| 桂林市| 石家庄市| 宝山区| 珠海市| 中阳县| 安庆市| 峨眉山市| 六安市| 应城市| 屏边| 馆陶县| 安陆市| 涟源市| 绥滨县| 惠水县| 天祝| 夏邑县| 延川县|