From: Daniel Lin <dlin.tw@gmail.com>
To: zsh-users@zsh.org
Subject: let unset array element remove compatible with bash
Date: Wed, 22 Feb 2012 03:28:48 +0000 [thread overview]
Message-ID: <CAPg-njyehwyETKY4KGdFV8u_ZwkMku-G9xVi7d7PpU9rZhdPDA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 983 bytes --]
As we know, bash is very common on Linux world.
So, even I've moved to zsh.
But, I wish my script could be compatible with bash.
Today, I found the array element remove is not compatible with bash.
Can any developer consider to enhance zsh's function like "unset var[2]"?
Here is the sample
$var[1]="four" ; var[2]="seven" ; var[3]="Four and
Seven"
$for v in "${var[@]}" ; do echo "$v" ;
done
four
seven
Four and
Seven
$for v in "${var[*]}" ; do echo "$v" ;
done
four seven Four and
Seven
$echo "${#var[@]} ${#var[1]} ${#var[2]} ${#var[3]}" # get
lengh
3 4 5
14
$unset var[2] ###### BASH only delete one
element
$var[2]=() ###### ZSH only delete one
element
$echo "${#var[@]} ${#var[1]} ${#var[2]}
${#var[3]}"
2 4 0 14
Another note, I wish the FAQ in zsh can explain this incompatible with bash.
$echo "${#var[@]} ${#var[1]} ${#var[2]} ${#var[3]}" # get lengh work both
bash/zsh
$echo "$#var $#var[1] $#var[2] $#var[3]" # get lengh work only zsh
next reply other threads:[~2012-02-22 3:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-22 3:28 Daniel Lin [this message]
2012-02-22 5:41 ` Bart Schaefer
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=CAPg-njyehwyETKY4KGdFV8u_ZwkMku-G9xVi7d7PpU9rZhdPDA@mail.gmail.com \
--to=dlin.tw@gmail.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).