> 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 ${va...@]}
> bash: va...@]: 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 [email protected] http://cnswww.cns.cwru.edu/~chet/