| Line | |
|---|
| 1 | # test the expansion of ${array[@]} and ${array[*]}, both quoted and
|
|---|
| 2 | # unquoted. the expansions should be exactly analogous to the
|
|---|
| 3 | # expansions of $@ and $* quoted and unquoted
|
|---|
| 4 | A=(a b)
|
|---|
| 5 |
|
|---|
| 6 | recho "${A[*]}"
|
|---|
| 7 |
|
|---|
| 8 | # If IFS is null, the parameters are joined without separators
|
|---|
| 9 | IFS=''
|
|---|
| 10 | recho "${A[*]}"
|
|---|
| 11 |
|
|---|
| 12 | # If IFS is unset, the parameters are separated by spaces
|
|---|
| 13 | unset IFS
|
|---|
| 14 | recho "${A[*]}"
|
|---|
| 15 |
|
|---|
| 16 | recho "${A[@]}"
|
|---|
| 17 | recho ${A[@]}
|
|---|
| 18 |
|
|---|
| 19 | IFS='/'
|
|---|
| 20 | A=(bob 'tom dick harry' joe)
|
|---|
| 21 | set ${A[*]}
|
|---|
| 22 | recho $#
|
|---|
| 23 | recho $1
|
|---|
| 24 | recho $2
|
|---|
| 25 | recho $3
|
|---|
| 26 |
|
|---|
| 27 | A=(bob 'tom dick harry' joe)
|
|---|
| 28 | set ${A[*]}
|
|---|
| 29 | recho $#
|
|---|
| 30 | recho $1
|
|---|
| 31 | recho $2
|
|---|
| 32 | recho $3
|
|---|
| 33 |
|
|---|
| 34 | A=(bob 'tom dick harry' joe)
|
|---|
| 35 | set ${A[@]}
|
|---|
| 36 | recho $#
|
|---|
| 37 | recho $1
|
|---|
| 38 | recho $2
|
|---|
| 39 | recho $3
|
|---|
| 40 |
|
|---|
| 41 | A=(bob 'tom dick harry' joe)
|
|---|
| 42 | set ${A[@]}
|
|---|
| 43 | recho $#
|
|---|
| 44 | recho $1
|
|---|
| 45 | recho $2
|
|---|
| 46 | recho $3
|
|---|
| 47 |
|
|---|
| 48 | # according to POSIX.2, unquoted $* should expand to multiple words if
|
|---|
| 49 | # $IFS is null, just like unquoted $@
|
|---|
| 50 | IFS=''
|
|---|
| 51 | A=(bob 'tom dick harry' joe)
|
|---|
| 52 | set "${A[*]}"
|
|---|
| 53 | recho $#
|
|---|
| 54 | recho $1
|
|---|
| 55 | recho $2
|
|---|
| 56 | recho $3
|
|---|
| 57 |
|
|---|
| 58 | A=(bob 'tom dick harry' joe)
|
|---|
| 59 | set ${A[*]}
|
|---|
| 60 | recho $#
|
|---|
| 61 | recho $1
|
|---|
| 62 | recho $2
|
|---|
| 63 | recho $3
|
|---|
| 64 |
|
|---|
| 65 | A=(bob 'tom dick harry' joe)
|
|---|
| 66 | set ${A[@]}
|
|---|
| 67 | recho $#
|
|---|
| 68 | recho $1
|
|---|
| 69 | recho $2
|
|---|
| 70 | recho $3
|
|---|
| 71 |
|
|---|
| 72 | # if IFS is unset, the individual positional parameters are split on
|
|---|
| 73 | # " \t\n" if $* or $@ are unquoted
|
|---|
| 74 | unset IFS
|
|---|
| 75 | A=(bob 'tom dick harry' joe)
|
|---|
| 76 | set ${A[*]}
|
|---|
| 77 | recho $#
|
|---|
| 78 | recho $1
|
|---|
| 79 | recho $2
|
|---|
| 80 | recho $3
|
|---|
| 81 |
|
|---|
| 82 | A=(bob 'tom dick harry' joe)
|
|---|
| 83 | set ${A[@]}
|
|---|
| 84 | recho $#
|
|---|
| 85 | recho $1
|
|---|
| 86 | recho $2
|
|---|
| 87 | recho $3
|
|---|
| 88 |
|
|---|
| 89 | # but not for "$@" or "$*"
|
|---|
| 90 | A=(bob 'tom dick harry' joe)
|
|---|
| 91 | set "${A[*]}"
|
|---|
| 92 | recho $#
|
|---|
| 93 | recho $1
|
|---|
| 94 | recho $2
|
|---|
| 95 | recho $3
|
|---|
| 96 |
|
|---|
| 97 | A=(bob 'tom dick harry' joe)
|
|---|
| 98 | set "${A[@]}"
|
|---|
| 99 | recho $#
|
|---|
| 100 | recho $1
|
|---|
| 101 | recho $2
|
|---|
| 102 | recho $3
|
|---|
| 103 |
|
|---|
| 104 | # these should both expand the value of A to multiple words
|
|---|
| 105 | A=(a b c d e)
|
|---|
| 106 | IFS=""
|
|---|
| 107 | recho ${A[@]}
|
|---|
| 108 | recho "${A[@]}"
|
|---|
| 109 |
|
|---|
| 110 | # this example is straight from the POSIX.2 rationale and adapted to arrays
|
|---|
| 111 | A=(foo bar bam)
|
|---|
| 112 |
|
|---|
| 113 | recho "${A[@]}"
|
|---|
| 114 | recho "${A[*]}"
|
|---|
| 115 |
|
|---|
| 116 | unset IFS
|
|---|
| 117 |
|
|---|
| 118 | recho "${A[@]}"
|
|---|
| 119 | recho ${A[@]}
|
|---|
| 120 | recho "${A[*]}"
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.