Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zip arrays exclude empty elements
- X-seq: zsh-users 26053
- From: sergio <sergio@xxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: zip arrays exclude empty elements
- Date: Sat, 5 Sep 2020 01:03:47 +0300
- Archived-at: <https://zsh.org/users/26053>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2020-09/0b12bc3e-6d96-db88-8e6c-2a3e1ca85c84%40outerface.net>
- Authentication-results: zsh.org; iprev=pass (outerface.net) smtp.remote-ip=195.70.199.109; dkim=pass header.d=outerface.net header.s=ed25519 header.a=ed25519-sha256; dkim=pass header.d=outerface.net header.s=rsa2048 header.a=rsa-sha256; dmarc=pass header.from=outerface.net; arc=none
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=outerface.net; s=rsa2048; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Date:Message-ID:Subject:From:To:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=nKP9XsBRmQ8L2ArQMyQnKMdywPrfVcy3aRd22R89QYY=; b=XxQ2xd7TSAbvm9UgDJTm4Ufe2k F3dQaMVSCtxmgs13ZYskzhtCmSizkJr3MS3AGlY+HMRl8wqXxtwttVO8FYtFuVUbnx+pW174U43sL Axo/yHUX7wlh7h2MuDKT8CiIcbFFZJuIoW+Eyd78flAl4PYoQJrBQbpVxzrwZ9KgEHQeXDKcL2uib 4O9C92VpbYJjPB8jgx8rJzgyxXJbZR7naKSW15J/uIMxPJUzKEl4JLCv7gsP/T3q4CWRNh9cgYciL k1imMBekzcfh16HYbuze1ZLxTY9i/+tRqa+uMaV+wFMfubhOf1J8/9gMPuJ3lO3xlm5m61egh6xNT Ejffo3ig==;
- Dkim-signature: v=1; a=ed25519-sha256; q=dns/txt; c=relaxed/relaxed; d=outerface.net; s=ed25519; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Date:Message-ID:Subject:From:To:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=nKP9XsBRmQ8L2ArQMyQnKMdywPrfVcy3aRd22R89QYY=; b=+zxB2Q6Zrh6DzFmOH/TSS0oKAA IMgINzai3Y7HlvqUlJ8K+9mbVoHu7mT52AgYE1Avlzn6REoHu7OLp3bNsBDw==;
- List-archive: <http://www.zsh.org/sympa/arc/zsh-users>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-users.zsh.org>
- List-owner: <mailto:zsh-users-request@zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-users>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-users>
- Sender: zsh-users-request@xxxxxxx
I have an input string in form of 'A[-][B]' that I'd like to translate
as follows:
1: A-B -> -a A -b B
2: A- -> -a A
3: A -> -a A
4: -B -> -b B
5: empty -> empty
The solution I found:
tmp=("${(@s.-.)crop}")
echo ${tmp[1]:+-a $tmp[1]} ${tmp[2]:+-b $tmp[2]}
But possible there is clearer and simpler solution, like
o=(-a -b)
echo ${o:^tmp}
or even
echo ${(-a -b):^${(@s.-.)crop}}
--
sergio.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author