bug-bash
[Top][All Lists]
Advanced

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

Re: Two states of empty arrays


From: Chet Ramey
Subject: Re: Two states of empty arrays
Date: Thu, 12 Dec 2019 14:13:12 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.0

On 12/12/19 12:08 PM, Léa Gris wrote:
Hello,

Depending on how an empty array is declared, it is not stored with the
same state.

# Empty array declared without parenthesis
unset myArr
declare -a myArr
typeset -p myArr
echo "${#myArr[@]}"

This is an unset variable with the array attribute; you have not assigned a
value.


# Empty array declared without parenthesis
unset myArr
declare -a myArr=()

This is an empty array variable; you have assigned a value.


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



reply via email to

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