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 |
|
64 |
#### } on the second line |
65 |
set -o errexit |
66 |
{ls; |
67 |
} |
68 |
## status: 127 |
69 |
|
70 |
#### Invalid for loop variable name |
71 |
for i.j in a b c; do |
72 |
echo hi |
73 |
done |
74 |
echo done |
75 |
## stdout-json: "" |
76 |
## status: 2 |
77 |
## OK mksh status: 1 |
78 |
## OK bash status: 0 |
79 |
## BUG bash stdout: done |
80 |
|
81 |
#### bad var name globally isn't parsed like an assignment |
82 |
# bash and dash disagree on exit code. |
83 |
FOO-BAR=foo |
84 |
## status: 127 |
85 |
|
86 |
#### bad var name in export |
87 |
# bash and dash disagree on exit code. |
88 |
export FOO-BAR=foo |
89 |
## status: 1 |
90 |
## OK dash status: 2 |
91 |
|
92 |
#### bad var name in local |
93 |
# bash and dash disagree on exit code. |
94 |
f() { |
95 |
local FOO-BAR=foo |
96 |
} |
97 |
f |
98 |
## status: 1 |
99 |
## OK dash status: 2 |
100 |
|
101 |
#### misplaced parentheses are not a subshell |
102 |
echo a(b) |
103 |
## status: 2 |
104 |
## OK mksh status: 1 |
105 |
|
106 |
#### incomplete command sub |
107 |
$(x |
108 |
## status: 2 |
109 |
## OK mksh status: 1 |
110 |
|
111 |
#### incomplete backticks |
112 |
`x |
113 |
## status: 2 |
114 |
## OK mksh status: 1 |
115 |
|
116 |
#### misplaced ;; |
117 |
echo 1 ;; echo 2 |
118 |
## stdout-json: "" |
119 |
## status: 2 |
120 |
## OK mksh status: 1 |
121 |
|
122 |
#### empty clause in [[ |
123 |
# regression test for commit 451ca9e2b437e0326fc8155783d970a6f32729d8 |
124 |
[[ || true ]] |
125 |
## status: 2 |
126 |
## N-I dash status: 0 |
127 |
## OK mksh status: 1 |
128 |
|
129 |
#### interactive parse error (regression) |
130 |
flags='' |
131 |
case $SH in |
132 |
*bash|*osh) |
133 |
flags='--rcfile /dev/null' |
134 |
;; |
135 |
esac |
136 |
$SH $flags -i -c 'var=)' |
137 |
|
138 |
## status: 2 |
139 |
## OK bash/mksh status: 1 |
140 |
|
141 |
#### array literal inside array is a parse error |
142 |
a=( inside=() ) |
143 |
echo len=${#a[@]} |
144 |
## status: 2 |
145 |
## stdout-json: "" |
146 |
## OK mksh status: 1 |
147 |
## BUG bash status: 0 |
148 |
## BUG bash stdout: len=0 |
149 |
|
150 |
#### array literal inside loop is a parse error |
151 |
f() { |
152 |
for x in a=(); do |
153 |
echo $x |
154 |
done |
155 |
echo done |
156 |
} |
157 |
## status: 2 |
158 |
## stdout-json: "" |
159 |
## OK mksh status: 1 |
160 |
|
161 |
#### array literal in case |
162 |
f() { |
163 |
case a=() in |
164 |
foo) |
165 |
echo hi |
166 |
;; |
167 |
esac |
168 |
} |
169 |
## status: 2 |
170 |
## stdout-json: "" |
171 |
## OK mksh status: 1 |
172 |
|
173 |
#### %foo=() is parse error (regression) |
174 |
|
175 |
# Lit_VarLike and then (, but NOT at the beginning of a word. |
176 |
|
177 |
f() { |
178 |
%foo=() |
179 |
} |
180 |
## status: 2 |
181 |
## stdout-json: "" |
182 |
## OK mksh status: 1 |
183 |
|
184 |
#### =word is not allowed |
185 |
=word |
186 |
## OK osh status: 2 |
187 |
## status: 127 |
188 |
|
189 |
#### echo =word is allowed |
190 |
echo =word |
191 |
## STDOUT: |
192 |
=word |
193 |
## END |