日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Shell函数参数

發(fā)布時間:2024/4/11 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Shell函数参数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在Shell中,調(diào)用函數(shù)時可以向其傳遞參數(shù)。在函數(shù)體內(nèi)部,通過 $n 的形式來獲取參數(shù)的值,例如,$1表示第一個參數(shù),$2表示第二個參數(shù)...

帶參數(shù)的函數(shù)示例:
  • #!/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 $# !" # 參數(shù)個數(shù)
  • echo "The string of the parameters is $* !" # 傳遞給函數(shù)的所有參數(shù)
  • }
  • 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ù),前面已經(jīng)提到:
    特殊變量說明
    $#傳遞給函數(shù)的參數(shù)個數(shù)。
    $*顯示所有傳遞給函數(shù)的參數(shù)。
    $@與$*相同,但是略有區(qū)別,請查看Shell特殊變量。
    $?函數(shù)的返回值。

    總結(jié)

    以上是生活随笔為你收集整理的Shell函数参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。