]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/comsub-posix.tests
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / comsub-posix.tests
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 #
14 : ${HOME:=/}
15
16 # works right
17 echo ab$(echo mnop)yz
18 # works right
19 echo ab$(echo mnop
20 )yz
21 #
22 # works right
23 echo $(echo ab
24 )
25 # works right
26 echo $(
27 )
28 echo $()
29 echo ab$()cd
30 echo ab$( )cd
31
32 echo $(case a in (a) echo sh_352.26ax; esac )
33 echo $(case a in (a) echo sh_352.26ay; esac)
34
35 echo $((echo sh_352.25a);(echo sh_352.25b))
36
37 echo $(echo sh_352.27 ')' ")" \)
38 # ) comment
39 )
40
41 echo $(
42 echo abc # a comment with )
43 )
44
45 echo $(
46 cat <<eof
47 here doc with )
48 eof
49 )
50
51 echo $(
52 echo ')'
53 )
54
55 unset x
56 x=$(cat <<"EOF"
57 bad' syntax
58 EOF
59 )
60 echo "$x"
61 unset x
62
63 echo $(for f in \); do echo a; done )
64 echo $(case a in a) echo sh_352.26a; esac )
65 echo $(case a in a) echo sh_352.26a; esac)
66
67 echo $(case a in
68 (a) echo sh_352.26
69 ;;
70 esac
71 )
72
73 echo $(case a in
74 a) echo sh_352.26
75 ;;
76 esac
77 )
78
79
80 echo $(case a in
81 a) echo sh_352.26
82 ;;
83
84
85
86
87
88 esac
89
90 )
91
92 echo $(( 4<(2+3) ? 1 : 32))
93
94 echo $(cat << end
95 sh_352.28 )
96 end
97 )
98
99 echo $(cat <<- end
100 sh_352.28 )
101 end
102 )
103
104 k=$(case x in x) echo k;; esac)
105 echo $k
106
107 x=$(
108 case $(ls) in
109 example) echo foobix;;
110 esac
111 )
112
113 echo $( echo ab\
114 cd)
115
116 echo `echo ab
117 cd`
118
119 echo `echo ab #xyz
120 cd`
121
122 echo "$(echo abcde)
123 "
124
125 recho "$(echo abcde)
126 "
127
128 echo $(echo abcde)\
129 foo
130
131 recho $(echo abcde)\
132 foo
133
134 recho "wx$(echo abcde)yz"
135 recho "$(echo abcde)"
136
137 echo $(cat <<eof
138 '
139 eof
140 )
141
142 echo after 1
143
144 echo $(cat <<\eof
145 '
146 eof
147 )
148
149 echo after 2
150
151 echo "$(cat <<\eof
152 '
153 eof
154 )"
155
156 echo after 3
157
158 echo "$(cat <<\eof
159 `
160 eof
161 )"
162
163 echo after 4
164
165 echo $(
166 cat << ')'
167 hello
168 )
169 )
170
171 echo after 5
172
173 echo $(cat <<'eof'
174 '
175 eof
176 )
177
178 echo after 6
179
180 echo $(
181 case x in x) echo x;; esac
182 )
183
184 echo $(
185 case x in x) echo x;; esac # followed by a comment
186 )
187
188 echo $(
189 case x in (x) echo x;; esac
190 )
191
192 echo $(
193 echo 'quoted )'
194 )
195
196 echo $(
197 echo comment # with )
198 )
199
200 echo $(
201 cat <<\eof
202 here-doc with )
203 eof
204 )
205
206 echo $(
207 cat <<\eof
208 here-doc with \()
209 eof
210 )
211
212 echo $(
213 cat <<\)
214 here-doc terminated with a parenthesis
215 )
216 )
217
218 echo $(
219 cat <<\eof
220 ' # or a single back- or doublequote
221 eof
222 )
223
224 echo $(
225 echo line terminated with a backslash # \
226 )
227
228 ${THIS_SH} ./comsub-posix1.sub
229
230 ${THIS_SH} ./comsub-posix2.sub
231
232 ${THIS_SH} ./comsub-posix3.sub
233
234 # produced a parse error through bash-4.0-beta2
235 : $(echo foo)"
236 "
237 # produced a parse error through bash-4.1
238 unset x
239 x=$(
240 echo yes
241 # a comment with " ' \
242 )
243 echo $x
244 unset x
245
246 # fixed after bash-4.0 released
247 : $(case a in a) echo ;; # comment
248 esac)
249
250 # fixed after bash-4.3 released
251 testing=$(
252 echo test | while read line; do
253 case $line in
254 test) echo saw test ;;
255 *) echo other ;;
256 esac
257 done
258 )
259
260 # recommended to be parsed as a nested comsub instead of arithsub
261 echo $(( echo ab cde ) )