[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Expanding an undefined array
From: |
Chet Ramey |
Subject: |
Re: Expanding an undefined array |
Date: |
Wed, 24 Sep 2008 23:57:54 -0400 |
User-agent: |
Thunderbird 2.0.0.16 (Macintosh/20080707) |
Bernd Eggink wrote:
> Is the following difference intentional, a bug, or do I miss something?
>
> unset a
> set -- "${a[@]}"
> echo $#
>
> Output: 0
This is correct.
> typeset a
> set -- "${a[@]}"
> echo $#
>
> Output: 1
The question is how to treat the variable created by `typeset'. Bash
has traditionally treated `typeset a' as equivalent to `typeset a=""'
instead of creating a `placeholder' variable that exists in a sort of
limbo. That's different from things like `export a' or `readonly a',
and probably inconsistent enough to be worth changing for bash-4.0.
That's the difference between the examples, not the expansion of
"${a[@]}".
Chet
Chet
>
> The man page says, "If the word is double-quoted, ... ${name[@]} expands
> each element of name to a separate word. When there are no array
> members, ${name[@]} expands to nothing." It doesn't mention a
> difference between an empty and an unset variable in this context. As a
> quoted 'nothing' normally counts 1 word, the 'nothing' in the first
> example appears to be some kind of 'super-nothing'.
>
> Regards,
> Bernd
>
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/