[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test -v difference between bash 5.1 and 5.2
From: |
Chet Ramey |
Subject: |
Re: test -v difference between bash 5.1 and 5.2 |
Date: |
Tue, 29 Aug 2023 11:44:13 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 |
On 8/29/23 11:38 AM, Kerin Millar wrote:
On Tue, 29 Aug 2023 11:24:43 -0400
Chet Ramey <chet.ramey@case.edu> wrote:
If you want to check whether an array variable is set, you can check
whether it has any set elements:
(( ${#assoc[@]} > 0 ))
This doesn't check whether an "array variable is set".
It checks whether there are any set elements. You have to assign a value
to set a variable.
Not only that, but the test will be true in the case that assoc has been
defined as a variable that is not an array.
One hopes that the shell programmer knows what variable types he's
using, and uses the appropriate constructs.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Re: test -v difference between bash 5.1 and 5.2, Kerin Millar, 2023/08/29