From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: Stephane Chazelas <stephane_cHaZelaS@yahoo.fr>
Cc: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: array expansion (Was: [bug-report] brace_ccl and $'\0' in ranges)
Date: Fri, 10 Oct 2003 21:16:57 +0100 [thread overview]
Message-ID: <20031010201658.0441A84E0@pwstephenson.fsnet.co.uk> (raw)
In-Reply-To: "Stephane Chazelas"'s message of "Tue, 07 Oct 2003 10:14:17 +0200." <20031007081417.GA418@pcchazelas.free.fr>
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@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk
parent reply other threads:[~2003-10-10 20:15 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20031007081417.GA418@pcchazelas.free.fr>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031010201658.0441A84E0@pwstephenson.fsnet.co.uk \
--to=pws@pwstephenson.fsnet.co.uk \
--cc=stephane_cHaZelaS@yahoo.fr \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).