1 |
#
|
2 |
# Differences from bash:
|
3 |
# - literal syntax alternates key-value
|
4 |
# - (@k) syntax for keys. Although this is sort of like my ${@array} syntax
|
5 |
# for arrays.
|
6 |
# - zsh allows $a[$k], not just ${a[$k]}
|
7 |
|
8 |
|
9 |
|
10 |
typeset -A a
|
11 |
a=(aa b foo bar a+1 c)
|
12 |
|
13 |
|
14 |
typeset -A a
|
15 |
a=(aa b foo bar a+1 c)
|
16 |
echo ${a[aa]}
|
17 |
## stdout: b
|
18 |
|
19 |
|
20 |
typeset -A a
|
21 |
a=(aa b foo bar a+1 c)
|
22 |
a[X]=XX
|
23 |
argv.py "${a[@]}"
|
24 |
# What order is this?
|
25 |
## stdout: ['bar', 'b', 'c', 'XX']
|
26 |
|
27 |
|
28 |
typeset -A assoc
|
29 |
assoc=(k1 v1 k2 v2 k3 v3)
|
30 |
for k in "${(@k)assoc}"; do
|
31 |
echo "$k: $assoc[$k]"
|
32 |
done
|
33 |
## stdout-json: "k1: v1\nk2: v2\nk3: v3\n"
|
34 |
|
35 |
|
36 |
typeset -A assoc
|
37 |
assoc=(k1 v1 k2 v2 k3 v3)
|
38 |
for k v ("${(@kv)assoc}"); do
|
39 |
echo "$k: $v"
|
40 |
done
|
41 |
## stdout-json: "k1: v1\nk2: v2\nk3: v3\n"
|
42 |
|
43 |
|
44 |
typeset -A assoc
|
45 |
assoc=(k1 v1 k2 v2 k3 v3)
|
46 |
echo ${#assoc} ${#assoc[k1]}
|
47 |
## stdout: 3 2
|
48 |
|
49 |
|
50 |
typeset -A assoc
|
51 |
assoc=(k1 v1 k2 v2 k3 v3)
|
52 |
argv.py "${assoc[1]}"
|
53 |
## stdout: ['']
|