<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免费放| 日韩av无码免费播放| 日本三级2019在线观看免费| 九月丁香婷婷亚洲综合色| kk4kk免费视频毛片| 亚洲性日韩精品国产一区二区| 久久亚洲中文无码咪咪爱| 日本免费网站观看| 国产成人亚洲精品播放器下载 | 亚洲色偷精品一区二区三区| 18禁网站免费无遮挡无码中文 | 人成电影网在线观看免费| 国产一区二区三区免费视频| 国产成人亚洲综合无| 免费夜色污私人影院在线观看| 精品特级一级毛片免费观看| 亚洲日韩在线中文字幕第一页 | 男女交性永久免费视频播放| 男男gay做爽爽免费视频| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 99视频在线看观免费| 91亚洲精品麻豆| 成人免费男女视频网站慢动作| 亚洲欧美日韩综合俺去了| 亚洲伦乱亚洲h视频| 老司机69精品成免费视频| 亚洲国产韩国一区二区| 午夜电影免费观看| 丰满人妻一区二区三区免费视频 | 亚洲五月午夜免费在线视频| 十八禁视频在线观看免费无码无遮挡骂过| 亚洲天堂中文资源| 国产在线观看免费不卡 | 国产免费AV片在线观看 | 亚洲人成电影院在线观看 | 亚洲欧洲∨国产一区二区三区| 在线涩涩免费观看国产精品| 亚洲精品456人成在线| 亚洲性日韩精品一区二区三区 | 男人天堂免费视频| 亚洲色无码专区一区|