From 33fe4f398c32ab65b71877277712b93f063ed63f Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Thu, 10 Mar 2022 23:12:35 +0100 Subject: zsh: key/value prefix for associative arrays --- src/tools/zsh.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tools/zsh.md b/src/tools/zsh.md index 7a07a31..ab50644 100644 --- a/src/tools/zsh.md +++ b/src/tools/zsh.md @@ -162,6 +162,18 @@ echo ${(L)foo} # aabb echo ${(U)foo} # AABB ``` +Key/values in associative arrays: +```zsh +typeset -A vec; vec[a]='aa'; vec[b]='bb' + +echo ${(k)vec} # a b +echo ${(v)vec} # aa bb +echo ${(kv)vec} # a aa b bb + +# Iterate over key value pairs. +for k v in ${(kv)vec)}; do ...; done +``` + ## Argument parsing with `zparseopts` ```zsh -- cgit v1.2.3