On 6/10/16 8:53 AM, psko...@gmail.com wrote: > Bash Version: 4.3 > Patch Level: 11 > Release Status: release > > Description: > [Detailed description of the problem, suggestion, or complaint.] > > Repeat-By: > #!/bin/bash > declare var > declare -a ary > declare -A asoc > > var=1 > ary=(1) > asoc[a]=1 > > for a in var ary asoc; do > printf '%s\t' "$a" > if test -v "$a"; then > echo ✓ > else > echo ✗ > fi > done > > <<OUTPUTS > var ✓ > ary ✓ > asoc ✗ > OUTPUTS
Referencing an array variable without a subscript is equivalent to referencing element 0 (or "0" for associative arrays). Plus, `test -v' works on variable names, not dereferenced variables or array elements. You can test whether or not a specific element is set by testing whether it is non-empty (test -v 'ary[1]'), or test whether an array has any elements set using something like [ ${#ary[@]} -gt 0 ]. One of the things that may come into a future version is something like test -v 'array[@]' to see whether or not an array has any elements set. Chet -- ``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/