On 11/26/16 1:01 PM, L A Walsh wrote: > But this didn't (misspelling of hash name): > >> if [[ ${requirs[xxx]:-} ]]; then echo ok; else echo not; fi > bash: xxx: unbound variable > > Shouldn't it have said: > > bash: requirs: unbound variable?
No. Bash performs array referencing `inside out', and always has. When asked to find the value for ${var[sub]}, bash first looks at `var' only to find out what kind of expansion `sub' has to undergo. In all cases, it expands `sub' for compatibility with other shells that implement arrays (primarily ksh93), because callers expect the side effects involved in expanding the array subscript to take place. In this case, it performs arithmetic expansion on the subscript, which involves expanding identifiers as variables, resulting in the `unbound variable' message. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/