Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: triviality regarding $# counts
On Sat, Apr 13, 2024 at 8:49 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>
> In a sense, you've been using it all along. Given an array "arr",
> $arr is the same as $arr[*] (by default), which is why double-quoting
> it produces a single word.
This puts me in mind of a couple of other details.
Because zsh does not split parameter expansions by default, $ary and
$ary[*] and $ary[@] are equivalent when not quoted, as Lawrence
demonstrated.
However, in all three of those cases, empty elements are typically
discarded, as they would be in a shell that defaults to splitting.
That's why "$ary[@]" is still useful: It quotes each element
individually, so empty elements are preserved.
(Aside, in bash and ksh, $ary is equivalent to ${ary[0]}, not to
${ary[*]}. A little oddly, this is also true for their associative
arrays, that is, the value for key 0 is used.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author