<kbd id="9plqc"><label id="9plqc"></label></kbd>

        <th id="9plqc"></th>
        1. <center id="9plqc"><video id="9plqc"></video></center>
          <sub id="9plqc"><form id="9plqc"><pre id="9plqc"></pre></form></sub>
          <nav id="9plqc"><form id="9plqc"><legend id="9plqc"></legend></form></nav>
          shell腳本函數(shù)及傳參 您所在的位置:網(wǎng)站首頁 屬羊人守護神是哪位菩薩 shell腳本函數(shù)及傳參

          shell腳本函數(shù)及傳參

          2023-10-28 16:38| 來源: 網(wǎng)絡整理| 查看: 265

          shell函數(shù)的定義

          shell腳本的函數(shù)位置相對自由,既可以一個shell腳本單獨成一個函數(shù), 也可以在主代碼中嵌入內(nèi)置函數(shù). 在Shell中可以通過下面的兩種語法來定義函數(shù),分別如下:

          function_name () { statement1 statement2 .... statementn }

          或者

          function function_name() { statement1 statement2 .... statementn } shell腳本函數(shù)傳參

          當某個函數(shù)定義好了以后,用戶就可以通過函數(shù)名來調(diào)用該函數(shù)了。在Shell中,函數(shù)調(diào)用的基本語法如下, function_name parm1 parm21 例如下面的腳本:

          #!/usr/bin/env bash # encoding: utf-8.0 function test_func() { echo "output from inside-function:test_func" echo 'input parameter1: '$1 echo 'input parameter2: '$2 } echo "here is main function" echo "now inside function: test_func" test_func hello world

          運行后輸出:

          here is main function now inside function: test_func input parameter1: hello input parameter2: world

          還可以更復雜一些.例如整個shell腳本還有控制臺的輸入?yún)?shù):

          #!/usr/bin/env bash # encoding: utf-8.0 function test_func() { echo "output from inside-function:test_func" echo 'input parameter1: '$1 echo 'input parameter2: '$2 } function print_list() { while read LINE do echo $LINE done < $1 } echo "here is main function" echo "now inside function: test_func" test_func hello world print_list $1

          運行./shell_function.test list.txt得到的輸出如下.可見內(nèi)置函數(shù)內(nèi)的參數(shù)列表和腳本的參數(shù)列表互相并不影響.

          here is main function now inside function: test_func output from inside-function:test_func input parameter1: hello input parameter2: world line1 line2 line3 line4


          【本文地址】

          公司簡介

          聯(lián)系我們

          今日新聞

          推薦新聞

          專題文章
            CopyRight 2018-2019 實驗室設備網(wǎng) 版權所有
            黄色免费网站在线看,韩国精品在线观看,韩国美女一区二区,99国产热 南康市| 轮台县| 荣成市| 建瓯市| 阿克苏市| 始兴县| 普宁市| 南昌市| 溧水县| 甘谷县| 武冈市| 寿阳县| 万盛区| 呼和浩特市| 永丰县| 吉木乃县| 南乐县| 麦盖提县| 土默特右旗| 万宁市| 和硕县| 北川| 漠河县| 永城市| 昭觉县| 山丹县| 名山县| 定日县| 贵州省| 保康县| 晋江市| 黑龙江省| 和林格尔县| 莎车县| 海口市| 台州市| 大化| 双鸭山市| 白水县| 襄城县| 潞西市| http://444 http://444 http://444 http://444 http://444 http://444