[Top][All Lists]

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

Re: Why is not every variable initialized to its data type specific defa

From: Chet Ramey
Subject: Re: Why is not every variable initialized to its data type specific default value upon declaration in Bash?
Date: Tue, 27 Nov 2012 12:16:49 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20121010 Thunderbird/16.0.1

On 11/27/12 5:03 AM, Tim Friske wrote:
> Hi folks,
> when I execute the following code in Bash version "GNU bash, version
> 4.1.10(4)-release (i686-pc-cygwin)", I get:
> declare a
> declare -p a
> # Output: -bash: declare: a: not found
> declare -i b
> declare -p b
> # Output: -bash: declare: b: not found
> declare -a c
> declare -p c
> # Output: declare -a c='()'
> declare -A d
> declare -p d
> # Output: declare -A d='()'
> Arguably I think that the above variables should either be initialized
> in all cases or in none of them. That would seem more consistent
> rather than initializing only arrays upon declaration.

Thanks for the report.  This is an artifact of how the arrays/hash tables
are initialized by `declare', as you suspect.  The variable should remain
undefined until explicitly assigned a value.  I will take a look and see
what effect that will have on other parts of the code.

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

reply via email to

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