From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: let unset array element remove compatible with bash
Date: Tue, 21 Feb 2012 21:41:37 -0800 [thread overview]
Message-ID: <120221214137.ZM13624@torch.brasslantern.com> (raw)
In-Reply-To: <CAPg-njyehwyETKY4KGdFV8u_ZwkMku-G9xVi7d7PpU9rZhdPDA@mail.gmail.com>
On Feb 22, 3:28am, Daniel Lin wrote:
}
} Can any developer consider to enhance zsh's function like "unset var[2]"?
}
} $unset var[2] ###### BASH only delete one element
} $var[2]=() ###### ZSH only delete one element
I've started a thread on zsh-workers about this, but:
var[3]=() does not mean the same thing that unset var[3] would imply.
In zsh, if you assign to a position that is "off the end" of the array,
zsh manufactures empty array elements to "fill in the gap". Try this
in each of bash and zsh:
unset gappy
gappy[9]=nine
for g in "${gappy[@]}"; do echo /$g/; done
Now in zsh:
unset gappy
gappy=(one)
gappy[3]=()
for g in "${gappy[@]}"; do echo /$g/; done
Note that assigning an empty array to the one-element slice gappy[3]
has caused gappy[2] to exist as an empty element.
Bash is using some kind of sparse structure to store its arrays.
next prev parent reply other threads:[~2012-02-22 5:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-22 3:28 Daniel Lin
2012-02-22 5:41 ` Bart Schaefer [this message]
2012-02-22 14:18 ` Chet Ramey
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=120221214137.ZM13624@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/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).