[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fwd: nounset option and arrays
From: |
Chet Ramey |
Subject: |
Re: Fwd: nounset option and arrays |
Date: |
Thu, 05 Feb 2009 14:54:53 -0500 |
User-agent: |
Thunderbird 2.0.0.19 (Macintosh/20081209) |
> In the following example, I was expecting var2 not to be seen as an unbound
> variable after it was declared. Wouldn't it be more consistent with the
> treatment of var1 not to issue the unbound variable error in this case? What
> is the rationale behind the current behavior?
>
> bash-3.2$ shopt -s -o nounset
> bash-3.2$ declare var1
> bash-3.2$ echo $var1
>
> bash-3.2$ declare -a var2
> bash-3.2$ echo $var2
> bash: var2: unbound variable
> bash-3.2$ echo ${var2[@]}
> bash: var2[@]: unbound variable
The bug is actually that the reference to var1 doesn't cause the shell to
exit. `declare' creates invisible "placeholder" variables that don't
actually exist until they're given a value. Until they have a value, they
should be treated as if they're unset.
Bash-4.0 treats both cases (array and scalar) as unset.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/