1
2 #### Bad var sub
3 echo $%
4 ## stdout: $%
5
6 #### Bad braced var sub -- not allowed
7 echo ${%}
8 ## status: 2
9 ## OK bash/mksh status: 1
10
11 #### Bad var sub caught at parse time
12 if test -f /; then
13 echo ${%}
14 else
15 echo ok
16 fi
17 ## status: 2
18 ## BUG dash/bash/mksh status: 0
19
20 #### Incomplete while
21 echo hi; while
22 echo status=$?
23 ## status: 2
24 ## stdout-json: ""
25 ## OK mksh status: 1
26
27 #### Incomplete for
28 echo hi; for
29 echo status=$?
30 ## status: 2
31 ## stdout-json: ""
32 ## OK mksh status: 1
33
34 #### Incomplete if
35 echo hi; if
36 echo status=$?
37 ## status: 2
38 ## stdout-json: ""
39 ## OK mksh status: 1
40
41 #### do unexpected
42 do echo hi
43 ## status: 2
44 ## stdout-json: ""
45 ## OK mksh status: 1
46
47 #### } is a parse error
48 }
49 echo should not get here
50 ## stdout-json: ""
51 ## status: 2
52 ## OK mksh status: 1
53
54 #### { is its own word, needs a space
55 # bash and mksh give parse time error because of }
56 # dash gives 127 as runtime error
57 {ls; }
58 echo "status=$?"
59 ## stdout-json: ""
60 ## status: 2
61 ## OK mksh status: 1
62
63 #### } on the second line
64 set -o errexit
65 {ls;
66 }
67 ## status: 127
68
69 #### Invalid for loop variable name
70 for i.j in a b c; do
71 echo hi
72 done
73 echo done
74 ## stdout-json: ""
75 ## status: 2
76 ## OK mksh status: 1
77 ## OK bash status: 0
78 ## BUG bash stdout: done
79
80 #### bad var name globally isn't parsed like an assignment
81 # bash and dash disagree on exit code.
82 FOO-BAR=foo
83 ## status: 127
84
85 #### bad var name in export
86 # bash and dash disagree on exit code.
87 export FOO-BAR=foo
88 ## status: 1
89 ## OK dash status: 2
90
91 #### bad var name in local
92 # bash and dash disagree on exit code.
93 f() {
94 local FOO-BAR=foo
95 }
96 f
97 ## status: 1
98 ## OK dash status: 2
99
100 #### misplaced parentheses are not a subshell
101 echo a(b)
102 ## status: 2
103 ## OK mksh status: 1
104
105 #### incomplete command sub
106 $(x
107 ## status: 2
108 ## OK mksh status: 1
109
110 #### incomplete backticks
111 `x
112 ## status: 2
113 ## OK mksh status: 1
114
115 #### misplaced ;;
116 echo 1 ;; echo 2
117 ## stdout-json: ""
118 ## status: 2
119 ## OK mksh status: 1
120
121 #### empty clause in [[
122 # regression test for commit 451ca9e2b437e0326fc8155783d970a6f32729d8
123 [[ || true ]]
124 ## status: 2
125 ## N-I dash status: 0
126 ## OK mksh status: 1
127
128 #### interactive parse error (regression)
129 flags=''
130 case $SH in
131 *bash|*osh)
132 flags='--rcfile /dev/null'
133 ;;
134 esac
135 $SH $flags -i -c 'var=)'
136
137 ## status: 2
138 ## OK bash/mksh status: 1
139
140 #### array literal inside array is a parse error
141 a=( inside=() )
142 echo len=${#a[@]}
143 ## status: 2
144 ## stdout-json: ""
145 ## OK mksh status: 1
146 ## BUG bash status: 0
147 ## BUG bash stdout: len=0
148
149 #### array literal inside loop is a parse error
150 f() {
151 for x in a=(); do
152 echo $x
153 done
154 echo done
155 }
156 ## status: 2
157 ## stdout-json: ""
158 ## OK mksh status: 1
159
160 #### array literal in case
161 f() {
162 case a=() in
163 foo)
164 echo hi
165 ;;
166 esac
167 }
168 ## status: 2
169 ## stdout-json: ""
170 ## OK mksh status: 1
171
172 #### %foo=() is parse error (regression)
173
174 # Lit_VarLike and then (, but NOT at the beginning of a word.
175
176 f() {
177 %foo=()
178 }
179 ## status: 2
180 ## stdout-json: ""
181 ## OK mksh status: 1
182
183 #### =word is not allowed
184 =word
185 ## OK osh status: 2
186 ## status: 127
187
188 #### echo =word is allowed
189 echo =word
190 ## STDOUT:
191 =word
192 ## END