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