<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Chan Chen Coding...

    Passing arguments to a shell script

    Any shell script you run has access to (inherits) the environment variables accessible to its parent shell. In addition, any arguments you type after the script name on the shell command line are passed to the script as a series of variables.
    The following parameters are recognized:
    $*
    Returns a single string (``$1, $2 ... $n'') comprising all of the positional parameters separated by the internal field separator character (defined by the IFS environment variable).
    $@
    Returns a sequence of strings (``$1'', ``$2'', ... ``$n'') wherein each positional parameter remains separate from the others.
    $1, $2 ... $n
    Refers to a numbered argument to the script, where n is the position of the argument on the command line. In the Korn shell you can refer directly to arguments where n is greater than 9 using braces. For example, to refer to the 57th positional parameter, use the notation ${57}. In the other shells, to refer to parameters with numbers greater than 9, use the shift command; this shifts the parameter list to the left. $1 is lost, while $2 becomes $1, $3 becomes $2, and so on. The inaccessible tenth parameter becomes $9 and can then be referred to.
    $0
    Refers to the name of the script itself.
    $#
    Refers to the number of arguments specified on a command line.
    For example, create the following shell script called mytest:
       echo There are $# arguments to $0: $*    echo first argument: $1    echo second argument: $2    echo third argument: $3    echo here they are again: $@ 
    When the file is executed, you will see something like the following:
       $ mytest foo bar quux    
    There are 3 arguments to mytest: foo bar quux    
    first argument: foo    
    second argument: bar    
    third argument: quux    

    here they are again: foo bar quux 
    $# is expanded to the number of arguments to the script, while $* and $@ contain the entire argument list. Individual parameters are accessed via $0, which contains the name of the script, and variables $1 to $3 which contain the arguments to the script (from left to right along the command line).
    Although the output from $@ and $* appears to be the same, it may be handled differently, as $@ lists the positional parameters separately rather than concatenating them into a single string. Add the following to the end of mytest:
       function how_many {         
            print "$# arguments were supplied."    
        }    
    how_many "$*"    
    how_many "$@" 
    The following appears when you run mytest:
       $ mytest foo bar quux    
    There are 3 arguments to mytest: foo bar quux    
    first argument: foo    
    second argument: bar  
    third argument: quux    
    here they are again: foo bar quux    1 arguments were supplied.    3 arguments were supplied.


    -----------------------------------------------------
    Silence, the way to avoid many problems;
    Smile, the way to solve many problems;

    posted on 2012-02-29 21:58 Chan Chen 閱讀(195) 評論(0)  編輯  收藏 所屬分類: Linux

    主站蜘蛛池模板: 亚洲国产精品成人AV在线| 久久亚洲免费视频| 亚洲精品理论电影在线观看| 最近的中文字幕大全免费8| 国产亚洲精品国产| 免费a级毛片无码a∨免费软件| 美腿丝袜亚洲综合| 两个人看的www高清免费观看| 在线亚洲午夜理论AV大片| 久久性生大片免费观看性| 亚洲国产精品一区二区久久hs | 亚洲日韩精品无码专区加勒比| 欧亚精品一区三区免费| 亚洲午夜无码久久久久软件| 日本高清免费aaaaa大片视频| 看免费毛片天天看| 国产亚洲一区二区三区在线不卡| 在线毛片片免费观看| 久久亚洲私人国产精品vA| 成人毛片视频免费网站观看| 美女啪啪网站又黄又免费| 亚洲日韩欧洲乱码AV夜夜摸| 69精品免费视频| 亚洲第一成年免费网站| 亚洲国产婷婷香蕉久久久久久| 日本在线免费观看| 亚洲天堂2017无码中文| 免费人成视频在线观看视频 | 亚洲网站免费观看| 免费黄网在线观看| 三级黄色片免费看| 亚洲短视频在线观看| 免费看一级做a爰片久久| 中文字幕的电影免费网站| 亚洲国产美女在线观看 | 67pao强力打造67194在线午夜亚洲 | 亚洲日本一线产区和二线| 亚洲精品无码你懂的网站| 在线人成精品免费视频| 国产AV无码专区亚洲AV琪琪| 久久久久久亚洲精品|