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: 2
92 ## OK bash/mksh status: 1
93
94 #### bad var name in local
95 # bash and dash disagree on exit code.
96 f() {
97 local FOO-BAR=foo
98 }
99 ## status: 2
100 ## BUG dash/bash/mksh status: 0
101
102 #### misplaced parentheses are not a subshell
103 echo a(b)
104 ## status: 2
105 ## OK mksh status: 1
106
107 #### incomplete command sub
108 $(x
109 ## status: 2
110 ## OK mksh status: 1
111
112 #### incomplete backticks
113 `x
114 ## status: 2
115 ## OK mksh status: 1
116
117 #### misplaced ;;
118 echo 1 ;; echo 2
119 ## stdout-json: ""
120 ## status: 2
121 ## OK mksh status: 1
122
123 #### empty clause in [[
124 # regression test for commit 451ca9e2b437e0326fc8155783d970a6f32729d8
125 [[ || true ]]
126 ## status: 2
127 ## N-I dash status: 0
128 ## OK mksh status: 1
129
130 #### interactive parse error (regression)
131 flags=''
132 case $SH in
133 *bash|*osh)
134 flags='--rcfile /dev/null'
135 ;;
136 esac
137 $SH $flags -i -c 'var=)'
138
139 ## status: 2
140 ## OK bash/mksh status: 1