bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: declare in a function makes a variable unable to be found with decla


From: Chet Ramey
Subject: Re: declare in a function makes a variable unable to be found with declare -p in some cases
Date: Thu, 19 Feb 2015 14:49:40 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 2/16/15 3:38 PM, SN wrote:

>         By the way, empty arrays seem to be reported as "not set".
>         a=(); test -v a || echo "not set"
>         This might be related (or not), but consider that the return
> status of `test -v'
>         is different on a bash version unaffected by the bug that I have
> tried (4.2.37).

References to an array without a subscript always reference element 0.
There's not really a clean way to check whether an array has been
declared but explicitly assigned an empty list, and it's not clear whether
or not an array without at least one assigned subscript should count as
`set' at all.

If you want to see whether or not an array has been assigned at least one
element, you can check whether ${#a[@]} > 0.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]