On 11/5/18 4:42 PM, Great Big Dot wrote: > Description: > The parameter expansion "${!var[@]}" expands to the indices of an array > (whether linear or associative). The expansion "${var-string}" > returns "${var}" iff var is set and 'string' otherwise. These two > features do not play well together:
You seem to have neglected a significant section of the documentation: "If the first character of parameter is an exclamation point (!), and parameter is not a nameref, it introduces a level of indirection. Bash uses the value formed by expanding the rest of parameter as the new parameter; this is then expanded and that value is used in the rest of the expansion, rather than the expansion of the original parameter. This is known as indirect expansion. The value is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion. If parameter is a nameref, this expands to the name of the parameter referenced by parameter instead of performing the complete indirect expansion. The exceptions to this are the expansions of ${!prefix*} and ${!name[@]} described below. The exclamation point must immediately follow the left brace in order to introduce indirec- tion." > $ declare -a -- array=([0]='helloworld') > $ printf -- '%s\n\n' "${!array[@]-Warning: unset}" > Warning: unset This happens to "work" because there is a single array element set, and it expands to a single word. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/