On 4/17/23 1:23 PM, Wiley Young wrote:

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:
         When an array 'a_foo' is created with 'mapfile -d '' -t', it is
tested with '[[ -v a_foo ]]' and '[[' returns 0. When '-O 1' is added to
mapfile, '[[ -v a_foo ]]' returns non-0.

This is because when you use an array variable name without a subscript,
it's treated as equivalent to using a subscript of 0.

If you want to check whether array a has any set elements, you can use
[[ -v a[@] ]] or [[ ${#a[@]} > 0 ]].

--
``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/


Reply via email to