On 11/19/14, 11:20 AM, Jason Vas Dias wrote: > Good day - > Please could anyone explain why the first command below produces no output: > $ ( declare -A a=([a]=1); if [ -v a ]; then echo yes; fi ) > $ ( declare -a a=([0]=1); if [ -v a ]; then echo yes; fi ) > yes > $
Dereferencing an array without a subscript is equivalent to referencing element 0 (integer or string, for indexed and associated arrays, respectively). Had you assigned the value to subscript 1 in the indexed array, you wouldn't have gotten `yes' either. If you want to test whether any element in an associative array is set, you can do that: if [ ${#a[@]} -gt 0 ]; then echo yes; fi -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/