diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2022-03-10 23:12:35 +0100 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2022-03-10 23:12:35 +0100 |
commit | 33fe4f398c32ab65b71877277712b93f063ed63f (patch) | |
tree | 17c085c08891f2d611846109eb88c167b881e99b /src/tools | |
parent | c57b2b348b2889ddcf94de5ccb147d40734345be (diff) | |
download | notes-33fe4f398c32ab65b71877277712b93f063ed63f.tar.gz notes-33fe4f398c32ab65b71877277712b93f063ed63f.zip |
zsh: key/value prefix for associative arrays
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/zsh.md | 12 |
1 files changed, 12 insertions, 0 deletions
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 |