Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: array expansion (Was: [bug-report] brace_ccl and $'\0' in ranges)
- X-seq: zsh-workers 19181
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
- To: Stephane Chazelas <stephane_cHaZelaS@xxxxxxxx>
- Subject: Re: array expansion (Was: [bug-report] brace_ccl and $'\0' in ranges)
- Date: Fri, 10 Oct 2003 21:16:57 +0100
- Cc: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- In-reply-to: "Stephane Chazelas"'s message of "Tue, 07 Oct 2003 10:14:17 +0200." <20031007081417.GA418@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Stephane Chazelas wrote:
> I've tried subscribing my other address at yahoo.fr, let's see.
Didn't seem to work. Here's what SpamAssassin says about your mail; it
ends up with a sizeable negative score, so I doubt if this helps.
X-Spam-Status: No, hits=-8.6 required=5.0
tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT,
RCVD_IN_OSIRUSOFT_COM,REFERENCES,REPLY_WITH_QUOTES,
USER_AGENT_MUTT
autolearn=ham version=2.55
X-Spam-Level:
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
> What is the historical reason why
>
> array=(1 "" "3 4")
> cmd $array
> # is cmd 1 "3 4"
>
> the empty arguments are stripped.
I suppose it's because the same thing happens with individual scalars.
An array element basically behaves as a scalar. (This is similar to other
shells.)
> I understand that zsh arrays are not hashes as in ksh or bash,
> and always start at index 1, even if you only define array[12],
> but wasn't it simpler to have:
>
> array=(1 "" "3 4")
> cmd $array
> # is cmd 1 "" "3 4"
> # and
> cmd ${array:#}
> # is cmd 1 "3 4"
>
> I more often need to use "${array[@]}" expansion, than the
> $array one.
> Note that the user guide is clear about this behavior, but not
> the manual. It says:
>
> | A subscript of the form `[*]' or `[@]' evaluates to all elements
> | of an array; [...] When an array parameter is referenced as
> | `$NAME' (with no subscript) it evaluates to `$NAME[*]'
>
> no reference about the empty elements implicit filtering.
>
> Same thing for
> var=
> cmd $var
> # turned into cmd
> # instead of cmd ""
> cmd ${var+$var}
> # would have made it.
>
> I end up having to use "$var" and "${array[@]}" everywhere as in
> other shells.
Yes, that's the long and short of it, if you need to preserve empty
array elements.
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk
Messages sorted by:
Reverse Date,
Date,
Thread,
Author