[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Documentation of expansion of "prefix ${arrayvar[@]} suffix"
From: |
Enrique Perez-Terron |
Subject: |
Documentation of expansion of "prefix ${arrayvar[@]} suffix" |
Date: |
Wed, 25 Aug 2004 21:55:23 +0200 |
Given the code
$ myarray=( arg1 arg2 arg3 )
$ for arg in "prefix ${myarray[@]} suffix"
> do
> echo "'$arg'"
> done
The documentation appears to suggest one should expect this:
'prefix '
'arg1'
'arg2'
'arg3'
' suffix'
rather than this (which is implemented):
'prefix arg1'
'arg2'
'arg3 suffix'
At least, that is how I read "each element .. a separate word".
Does any standard specify what is the right thing to do?
If not, is there any reason to prefer one over the other?
Suggested rephrasing:
If
the word is double-quoted, ${name[*]} expands to a single word with the
value of each array member separated by the first character of the IFS
- special variable, and ${name[@]} expands each element of name to a sep-
- arate word.
+ special variable, and ${name[@]} expands each element of name except the
+ first and last, to a separate word, while the first and last elements
+ become contiguous with any preceding and following parts respectively,
+ of the word.
or
+ special variable, and ${name[@]} substitutes the array members and splits
+ the resulting word where the first character of the IFS special variable
+ would have been inserted had the index been specified as "*". Thus, the
+ word "prefix ${name[@]} suffix" expands to as many words as there are members
+ of the array if there is at least one member, or to one word if there are no
+ members but the word, as here, has other characters.
It seems like the other behavior is easier to describe. <taunt>Could it be that
it is more intuitive?</taunt>
Regards,
Enrique
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Documentation of expansion of "prefix ${arrayvar[@]} suffix",
Enrique Perez-Terron <=