<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

    主站蜘蛛池模板: 69xx免费观看视频| 国产精品小视频免费无限app| 免费国产成人α片| 久久精品国产精品亚洲| 日韩成人毛片高清视频免费看| 久久精品无码一区二区三区免费| 亚洲精品**中文毛片| 99视频精品全部免费观看| 亚洲邪恶天堂影院在线观看| 91香蕉国产线在线观看免费| 亚洲精品免费在线视频| 91短视频在线免费观看| 亚洲国产品综合人成综合网站| 18观看免费永久视频| 亚洲偷偷自拍高清| 日韩精品免费一区二区三区| 在线视频亚洲一区| 久久久久久亚洲精品不卡| 国精产品一区一区三区免费视频| 亚洲婷婷五月综合狠狠爱| a视频在线观看免费| 久久精品国产亚洲AV大全| 免费专区丝袜脚调教视频| 亚洲色精品三区二区一区| 成人永久免费高清| 久青草视频97国内免费影视| 婷婷久久久亚洲欧洲日产国码AV| 青青青国产在线观看免费网站| 亚洲日本在线电影| 国产精品亚洲mnbav网站| 女人体1963午夜免费视频| 久久精品国产99国产精品亚洲| 免费看无码自慰一区二区| 无码毛片一区二区三区视频免费播放| 亚洲热妇无码AV在线播放| 6080午夜一级毛片免费看| 美女尿口扒开图片免费| 久久噜噜噜久久亚洲va久| 成人免费看片又大又黄| 香蕉免费一级视频在线观看| 亚洲人成电影在线观看网|