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