Professional Web Applications Themes

Bash: How to expand multiple positional parameters - UNIX Programming

Hello, In bash, is there a way to specify the expansion of several adjacent positional parameters at once? For example, in tcsh, say $argv[2-7], or $argv[4-]. Thanks. Fred -- Fred Ma Dept. of Electronics, Carleton University 1125 Colonel By Drive, Ottawa, Ontario Canada, K1S 5B6...

  1. #1

    Default Bash: How to expand multiple positional parameters

    Hello,

    In bash, is there a way to specify the
    expansion of several adjacent positional
    parameters at once? For example, in
    tcsh, say $argv[2-7], or $argv[4-].
    Thanks.

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

  2. #2

    Default Re: Bash: How to expand multiple positional parameters

    Fred Ma <carleton.ca> wrote: 

    ${*:2:5}
    ${*:4}

    --
    William Park, Open Geometry Consulting, <ca>
    Linux solution for data management and processing.
    William Guest

  3. #3

    Default Re: Bash: How to expand multiple positional parameters

    William Park wrote: 
    >
    > ${*:2:5}
    > ${*:4}
    >
    > --
    > William Park, Open Geometry Consulting, <ca>
    > Linux solution for data management and processing.[/ref]


    William,

    Thanks. More importantly, where is this doented?
    I've was reading the gnu man pages on cygwin, solaris,
    and various web tutorials for bash, but was not able
    to find this syntax.

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

  4. #4

    Default Re: Bash: How to expand multiple positional parameters

    On Fri, 13 Feb 2004 at 22:40 GMT, Fred Ma wrote: 
    >>
    >> ${*:2:5}
    >> ${*:4}
    >>
    >> --
    >> William Park, Open Geometry Consulting, <ca>
    >> Linux solution for data management and processing.[/ref]
    >
    >
    > William,
    >
    > Thanks. More importantly, where is this doented?
    > I've was reading the gnu man pages on cygwin, solaris,
    > and various web tutorials for bash, but was not able
    > to find this syntax.[/ref]

    It is (and isn't) doented in the man page:

    Parameter Expansion
    .......
    ${parameter:offset}
    ${parameter:offset:length}
    Substring Expansion. Expands to up to length characters of
    parameter starting at the character specified by offset. If
    length is omitted, expands to the substring of parameter start-
    ing at the character specified by offset. length and offset are
    arithmetic expressions (see ARITHMETIC EVALUATION below).
    length must evaluate to a number greater than or equal to zero.
    If offset evaluates to a number less than zero, the value is
    used as an offset from the end of the value of parameter. If
    parameter is , the result is length positional parameters
    beginning at offset. If parameter is an array name indexed by
    or *, the result is the length members of the array beginning
    with ${parameter[offset]}. Substring indexing is zero-based
    unless the positional parameters are used, in which case the
    indexing starts at 1.
    ......
    ##EOMP

    ${*:2:2} can be inferred from the above paragraph. These are stated
    explicitly:

    ${:2:5}
    ${:4}

    ...and should usually be used quoted, so that multi-word
    parameters are not split:

    $ set a b 'c d' e f g h
    $ printf "%s\n" "${:2:3}"
    b
    c d
    e

    --
    Chris F.A. Johnson http://cfaj.freeshell.org
    ================================================== =================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
    Chris Guest

  5. #5

    Default Re: Bash: How to expand multiple positional parameters

    "Chris F.A. Johnson" wrote: 


    Thanks, Chris. I was looking in the section about
    Positional Parameters (wrong section).

    Fred
    --
    Fred Ma
    Dept. of Electronics, Carleton University
    1125 Colonel By Drive, Ottawa, Ontario
    Canada, K1S 5B6
    Fred Guest

Similar Threads

  1. Replies: 2
    Last Post: August 5th, 10:07 AM
  2. Replies: 4
    Last Post: November 28th, 05:28 PM
  3. Funtions With Multiple Parameters
    By Brij in forum Microsoft SQL / MS SQL Server
    Replies: 2
    Last Post: August 7th, 07:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139