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