1 #
2 # Corner cases for assignment that we're not handling now.
3
4 #### typeset a[3]=4
5 typeset a[3]=4 a[5]=6
6 echo status=$?
7 argv.py "${!a[@]}" "${a[@]}"
8 ## STDOUT:
9 status=0
10 ['3', '5', '4', '6']
11 ## END
12
13 #### typeset -a a[1]=a a[3]=c
14 # declare works the same way in bash, but not mksh.
15 # spaces are NOT allowed here.
16 typeset -a a[1*1]=x a[1+2]=z
17 argv.py "${a[@]}"
18 ## stdout: ['x', 'z']
19
20 #### local a[3]=4
21 f() {
22 local a[3]=4 a[5]=6
23 echo status=$?
24 argv.py "${!a[@]}" "${a[@]}"
25 }
26 f
27 ## STDOUT:
28 status=0
29 ['3', '5', '4', '6']
30 ## END
31
32 #### readonly a[7]=8
33 readonly b[7]=8
34 echo status=$?
35 argv.py "${!b[@]}" "${b[@]}"
36 ## STDOUT:
37 status=0
38 ['7', '8']
39 ## END
40
41 # bash doesn't like this variable name!
42 ## N-I bash STDOUT:
43 status=1
44 []
45 ## END
46
47 #### export a[7]=8
48 export a[7]=8
49 echo status=$?
50 argv.py "${!a[@]}" "${a[@]}"
51 printenv.py a
52 ## STDOUT:
53 status=1
54 []
55 None
56 ## END
57 ## OK osh STDOUT:
58 status=2
59 []
60 None
61 ## END
62 ## BUG mksh STDOUT:
63 status=0
64 ['7', '8']
65 None
66 ## END
67
68 #### 'builtin' prefix is allowed on assignments
69 builtin export e='E'
70 echo e=$e
71 ## STDOUT:
72 e=E
73 ## END
74 ## N-I dash STDOUT:
75 e=
76 ## END
77
78 #### 'command' prefix is allowed on assignments
79 readonly r1='R1' # zsh has this
80 command readonly r2='R2' # but not this
81 echo r1=$r1
82 echo r2=$r2
83 ## STDOUT:
84 r1=R1
85 r2=R2
86 ## END
87 ## N-I zsh STDOUT:
88 r1=R1
89 r2=
90 ## END
91
92 #### 'builtin' prefix and array is a parse error
93 builtin typeset a=(1 2 3)
94 echo len=${#a[@]}
95 ## stdout-json: ""
96 ## status: 2
97 ## OK mksh status: 1
98
99 #### 'command' prefix and array is a parse error
100 command typeset a=(1 2 3)
101 echo len=${#a[@]}
102 ## stdout-json: ""
103 ## status: 2
104 ## OK mksh status: 1
105