Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
let unset array element remove compatible with bash
- X-seq: zsh-users 16778
- From: Daniel Lin <dlin.tw@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: let unset array element remove compatible with bash
- Date: Wed, 22 Feb 2012 03:28:48 +0000
- Authentication-results: mr.google.com; spf=pass (google.com: domain of dlin.tw@xxxxxxxxx designates 10.152.115.38 as permitted sender) smtp.mail=dlin.tw@xxxxxxxxx; dkim=pass header.i=dlin.tw@xxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=NLqGeTwJgxZzMSc6XCWGkKo/9z6asGdiUi3Ek8gqBvg=; b=xX/dIrvWgaAxDm0gt4GAaFHUGS7YTwW5piRv8o248pzl0Tzb2YtF4BfVOLpvaW1DlI m6TmRSyildCg/FlXRcWvCHjcXydY52n+VqlKlHV8IXGyjb3ZdUZAA/tlnLYrNlRUyYoD wna1xnj3aOoA0Ey4ryJnmvowIsf0bvYmeIEGo=
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author