1 |
#!/bin/bash |
2 |
|
3 |
#### K and V are variables in (( array[K] = V )) |
4 |
K=5 |
5 |
V=42 |
6 |
typeset -a array |
7 |
(( array[K] = V )) |
8 |
|
9 |
echo array[5]=${array[5]} |
10 |
echo keys = ${!array[@]} |
11 |
echo values = ${array[@]} |
12 |
## STDOUT: |
13 |
array[5]=42 |
14 |
keys = 5 |
15 |
values = 42 |
16 |
## END |
17 |
|
18 |
#### when are variables set with 'test -v' |
19 |
test -v unset |
20 |
echo unset=$? |
21 |
|
22 |
typeset -a a |
23 |
test -v a |
24 |
echo a=$? |
25 |
|
26 |
typeset -A A |
27 |
test -v A |
28 |
echo A=$? |
29 |
|
30 |
a[0]=1 |
31 |
A['x']=x |
32 |
|
33 |
test -v a |
34 |
echo a=$? |
35 |
|
36 |
# NOTE: This is a BUG! A is set |
37 |
test -v A |
38 |
echo A=$? |
39 |
|
40 |
## STDOUT: |
41 |
unset=1 |
42 |
a=1 |
43 |
A=1 |
44 |
a=0 |
45 |
A=0 |
46 |
## END |
47 |
## BUG bash STDOUT: |
48 |
unset=1 |
49 |
a=1 |
50 |
A=1 |
51 |
a=0 |
52 |
A=1 |
53 |
## END |
54 |
## N-I mksh STDOUT: |
55 |
unset=2 |
56 |
a=2 |
57 |
A=2 |
58 |
a=2 |
59 |
A=2 |
60 |
## END |