T.misc revision 1.1.1.1 1 1.1 christos #!/bin/sh
2 1.1 christos
3 1.1 christos echo T.misc: miscellaneous buglets now watched for
4 1.1 christos
5 1.1 christos awk=${awk-../a.out}
6 1.1 christos
7 1.1 christos rm -f core
8 1.1 christos
9 1.1 christos echo 'The big brown over the lazy doe
10 1.1 christos The big brown over the lazy dog
11 1.1 christos x
12 1.1 christos The big brown over the lazy dog' >foo
13 1.1 christos echo 'failed
14 1.1 christos succeeded
15 1.1 christos failed
16 1.1 christos succeeded' >foo1
17 1.1 christos $awk '{ if (match($0, /^The big brown over the lazy dog/) == 0) {
18 1.1 christos printf("failed\n")
19 1.1 christos } else {
20 1.1 christos printf("succeeded\n")
21 1.1 christos }
22 1.1 christos } ' foo >foo2
23 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc ghosh RE bug'
24 1.1 christos
25 1.1 christos echo '123
26 1.1 christos 1234567890
27 1.1 christos 12345678901' >foo
28 1.1 christos echo '12345678901' >foo1
29 1.1 christos $awk 'length($0) > 10' foo >foo2
30 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc last number bug'
31 1.1 christos
32 1.1 christos # check some \ sequences in strings (ascii)
33 1.1 christos echo HIJKL >foo1
34 1.1 christos echo foo | $awk '{ print "H\x49\x4a\x4BL" }' >foo2
35 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc hex string cvt'
36 1.1 christos
37 1.1 christos echo 012x45 >foo1
38 1.1 christos $awk 'BEGIN { print "0\061\62x\0645" }' >foo2
39 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc oct string cvt'
40 1.1 christos
41 1.1 christos # $i++ means ($i)++
42 1.1 christos echo 3 5 | $awk '{ i = 1; print $i++ ; print $1, i }' >foo1
43 1.1 christos echo '3
44 1.1 christos 4 1' >foo2
45 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc bad field increment'
46 1.1 christos
47 1.1 christos # makes sure that fields are recomputed even if self-assignment
48 1.1 christos # take into account that subtracting from NF now rebuilds the record
49 1.1 christos echo 'a b c
50 1.1 christos s p q r
51 1.1 christos x y z' >foo
52 1.1 christos echo 'a
53 1.1 christos s p
54 1.1 christos x' >foo1
55 1.1 christos $awk '{ NF -= 2; $1 = $1; print }' <foo >foo2
56 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad field self-assignment"
57 1.1 christos
58 1.1 christos echo '1
59 1.1 christos 1' >foo1
60 1.1 christos $awk 'BEGIN {x = 1; print x; x = x; print x}' >foo2
61 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad self-assignment"
62 1.1 christos
63 1.1 christos echo 573109312 | $awk '{print $1*4}' >foo1
64 1.1 christos echo 2292437248 >foo2
65 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad overflow"
66 1.1 christos
67 1.1 christos # note that there are 8-bit characters in the echo
68 1.1 christos # some shells will probably screw this up.
69 1.1 christos echo '#
70 1.1 christos code 1
71 1.1 christos code 2' |
72 1.1 christos $awk '/^#/' >foo1
73 1.1 christos echo '#' >foo2
74 1.1 christos diff foo1 foo2 || echo 1>&2 "BAD: T.misc bad match of 8-bit char"
75 1.1 christos
76 1.1 christos echo hello |
77 1.1 christos $awk 'BEGIN { FILENAME = "/etc/passwd" }
78 1.1 christos { print $0 }' >/dev/null
79 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc /etc/passwd dropped core"; fi
80 1.1 christos
81 1.1 christos echo hello |
82 1.1 christos $awk ' function foo(foo) {
83 1.1 christos foo = 1
84 1.1 christos foo()
85 1.1 christos }
86 1.1 christos { foo(bar) }
87 1.1 christos ' >/dev/null 2>&1
88 1.1 christos if test -r core; then
89 1.1 christos echo 1>&2 "BAD: T.misc function foo(foo) dropped core"
90 1.1 christos rm -f core
91 1.1 christos fi
92 1.1 christos
93 1.1 christos echo '2
94 1.1 christos 10' |
95 1.1 christos $awk '{ x[NR] = $0 } # test whether $0 is NUM as well as STR
96 1.1 christos END { if (x[1] > x[2]) print "BAD: T.misc: $0 is not NUM" }'
97 1.1 christos
98 1.1 christos
99 1.1 christos $awk 'BEGIN {
100 1.1 christos npad = substr("alexander" " ",1,15)
101 1.1 christos print npad
102 1.1 christos }' >foo
103 1.1 christos grep '\\' foo && echo 1>&2 "BAD: T.misc alexander fails"
104 1.1 christos
105 1.1 christos # This should give an error about function arguments
106 1.1 christos $awk '
107 1.1 christos function foo(x) { print "x is" x }
108 1.1 christos BEGIN { foo(foo) }
109 1.1 christos ' 2>foo
110 1.1 christos grep "can't use function foo" foo >/dev/null || echo 1>&2 "BAD: T.misc fcn args"
111 1.1 christos
112 1.1 christos
113 1.1 christos # gawk defref test; should give error about undefined function
114 1.1 christos $awk 'BEGIN { foo() }' 2>foo
115 1.1 christos grep "calling undefined function foo" foo >/dev/null || echo 1>&2 "BAD: T.misc undefined function"
116 1.1 christos
117 1.1 christos
118 1.1 christos # gawk arrayparm test; should give error about function
119 1.1 christos $awk '
120 1.1 christos BEGIN {
121 1.1 christos foo[1]=1;
122 1.1 christos foo[2]=2;
123 1.1 christos bug1(foo);
124 1.1 christos }
125 1.1 christos function bug1(i) {
126 1.1 christos for (i in foo) {
127 1.1 christos bug2(i);
128 1.1 christos delete foo[i];
129 1.1 christos print i,1,bot[1];
130 1.1 christos }
131 1.1 christos }
132 1.1 christos function bug2(arg) {
133 1.1 christos bot[arg]=arg;
134 1.1 christos }
135 1.1 christos ' 2>foo
136 1.1 christos grep "can.t assign to foo" foo >/dev/null || echo 1>&2 "BAD: T.misc foo bug"
137 1.1 christos
138 1.1 christos
139 1.1 christos # This should be a syntax error
140 1.1 christos $awk '
141 1.1 christos !x = y
142 1.1 christos ' 2>foo
143 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error !x=y fails"
144 1.1 christos
145 1.1 christos # This should print bbb
146 1.1 christos $awk '
147 1.1 christos BEGIN { up[1] = "a"
148 1.1 christos for (i in up) gsub("a", "A", x)
149 1.1 christos print x x "bbb"
150 1.1 christos exit
151 1.1 christos }
152 1.1 christos ' >foo
153 1.1 christos grep bbb foo >/dev/null || echo 1>&2 "BAD: T.misc gsub failed"
154 1.1 christos
155 1.1 christos echo yes |
156 1.1 christos $awk '
157 1.1 christos BEGIN {
158 1.1 christos printf "push return" >"/dev/null"
159 1.1 christos getline ans <"/dev/null"
160 1.1 christos } '
161 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc getline ans dropped core"; fi
162 1.1 christos
163 1.1 christos $awk 'BEGIN { unireghf() }
164 1.1 christos function unireghf(hfeed) { hfeed[1] = 0 }'
165 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc unireghf dropped core"; fi
166 1.1 christos
167 1.1 christos echo x | $awk '/[/]/' 2>foo
168 1.1 christos grep 'nonterminated character class' foo >/dev/null || error 'BAD: T.misc nonterminated fails'
169 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc nonterminated dropped core"; fi
170 1.1 christos
171 1.1 christos $awk '
172 1.1 christos function f() { return 12345 }
173 1.1 christos BEGIN { printf "<%s>\n", f() }
174 1.1 christos ' >foo
175 1.1 christos grep '<12345>' foo >/dev/null || echo 'BAD: T.misc <12345> fails'
176 1.1 christos
177 1.1 christos echo 'abc
178 1.1 christos def
179 1.1 christos
180 1.1 christos ghi
181 1.1 christos jkl' >foo
182 1.1 christos $awk '
183 1.1 christos BEGIN { RS = ""
184 1.1 christos while (getline <"foo")
185 1.1 christos print
186 1.1 christos }' >foo1
187 1.1 christos $awk 'END {print NR}' foo1 | grep 4 >/dev/null || echo 'BAD: T.misc abcdef fails'
188 1.1 christos
189 1.1 christos
190 1.1 christos # The following should not produce a warning about changing a constant
191 1.1 christos # nor about a curdled tempcell list
192 1.1 christos $awk 'function f(x) { x = 2 }
193 1.1 christos BEGIN { f(1) }' >foo
194 1.1 christos grep '^' foo && echo 'BAD: test constant change fails'
195 1.1 christos
196 1.1 christos # The following should not produce a warning about a curdled tempcell list
197 1.1 christos $awk 'function f(x) { x }
198 1.1 christos BEGIN { f(1) }' >foo
199 1.1 christos grep '^' foo && echo 'BAD: test tempcell list fails'
200 1.1 christos
201 1.1 christos $awk 'BEGIN { print 9, a=10, 11; print a; exit }' >foo1
202 1.1 christos echo '9 10 11
203 1.1 christos 10' >foo2
204 1.1 christos diff foo1 foo2 || echo 'BAD: T.misc (embedded expression)'
205 1.1 christos
206 1.1 christos echo "abc defgh ijkl" | $awk '
207 1.1 christos { $1 = ""; line = $0; print line; print $0; $0 = line; print $0 }' >foo1
208 1.1 christos echo " defgh ijkl
209 1.1 christos defgh ijkl
210 1.1 christos defgh ijkl" >foo2
211 1.1 christos diff foo1 foo2 || echo 'BAD: T.misc (assignment to $0)'
212 1.1 christos
213 1.1 christos $awk '
214 1.1 christos function min(a, b)
215 1.1 christos {
216 1.1 christos if (a < b)
217 1.1 christos return a
218 1.1 christos else
219 1.1 christos return b
220 1.1 christos }
221 1.1 christos BEGIN { exit }
222 1.1 christos '
223 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc function min dropped core"; fi
224 1.1 christos
225 1.1 christos # The following should not give a syntax error message:
226 1.1 christos $awk '
227 1.1 christos function expand(chart) {
228 1.1 christos getline chart < "CHAR.ticks"
229 1.1 christos }
230 1.1 christos ' >foo
231 1.1 christos grep '^' foo >/dev/null && echo 'BAD: T.misc expand error'
232 1.1 christos
233 1.1 christos $awk 'BEGIN { print 1e40 }' >/dev/null
234 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc 1E40 dropped core"; fi
235 1.1 christos
236 1.1 christos # The following syntax error should not dump core:
237 1.1 christos $awk '
238 1.1 christos $NF==3 {first=1}
239 1.1 christos $NF==2 && first==0 && (abs($1-o1)>120||abs($2-o2)>120) {print $0}
240 1.1 christos $NF==2 {o1=%1; o2=$2; first=0}
241 1.1 christos ' 2>/dev/null
242 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc first/abs dropped core"; fi
243 1.1 christos
244 1.1 christos # The following syntax error should not dump core:
245 1.1 christos $awk '{ n = split($1, address, !); print address[1] }' 2>foo
246 1.1 christos grep 'illegal statement' foo >/dev/null || echo 'BAD: T.misc split error'
247 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc split! dropped core"; fi
248 1.1 christos
249 1.1 christos # The following should cause a syntax error message
250 1.1 christos $awk 'BEGIN {"hello"}' 2>foo
251 1.1 christos grep 'illegal statement' foo >/dev/null || echo 'BAD: T.misc hello error'
252 1.1 christos
253 1.1 christos # The following should give a syntax error message:
254 1.1 christos $awk '
255 1.1 christos function pile(c, r) {
256 1.1 christos r = ++pile[c]
257 1.1 christos }
258 1.1 christos
259 1.1 christos { pile($1) }
260 1.1 christos ' 2>foo
261 1.1 christos grep 'context is' foo >/dev/null || echo 'BAD: T.misc pile error'
262 1.1 christos
263 1.1 christos # This should complain about missing atan2 argument:
264 1.1 christos $awk 'BEGIN { atan2(1) }' 2>foo
265 1.1 christos grep 'requires two arg' foo >/dev/null || echo 'BAD: T.misc atan2 error'
266 1.1 christos
267 1.1 christos # This should not core dump:
268 1.1 christos $awk 'BEGIN { f() }
269 1.1 christos function f(A) { delete A[1] }
270 1.1 christos '
271 1.1 christos if test -r core; then echo 1>&2 "BAD: T.misc delete dropped core"; fi
272 1.1 christos
273 1.1 christos # nasty one: should not be able to overwrite constants
274 1.1 christos $awk 'BEGIN { gsub(/ana/,"anda","banana")
275 1.1 christos printf "the monkey ate a %s\n", "banana" }
276 1.1 christos ' >/dev/null 2>foo
277 1.1 christos grep 'syntax error' foo >/dev/null || echo 'BAD: T.misc gsub banana error'
278 1.1 christos
279 1.1 christos # nasty one: should not be able to overwrite constants
280 1.1 christos $awk 'BEGIN { sub(/ana/,"anda","banana")
281 1.1 christos printf "the monkey ate a %s\n", "banana" }
282 1.1 christos ' >/dev/null 2>foo
283 1.1 christos grep 'syntax error' foo >/dev/null || echo 'BAD: T.misc sub banana error'
284 1.1 christos
285 1.1 christos # line numbers used to double-count comments
286 1.1 christos $awk '#
287 1.1 christos #
288 1.1 christos #
289 1.1 christos /x
290 1.1 christos ' >/dev/null 2>foo
291 1.1 christos grep 'line [45]' foo >/dev/null || echo 'BAD: T.misc lineno'
292 1.1 christos
293 1.1 christos echo 'x
\y' >foo1
297 1.1 christos $awk 'BEGIN { print "x\f\r\b\v\a\\y" }' >foo2
298 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc weird chars'
299 1.1 christos
300 1.1 christos echo 0 >foo1
301 1.1 christos $awk ' BEGIN { exit }
302 1.1 christos { print }
303 1.1 christos END { print NR }' >foo2
304 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc BEGIN exit'
305 1.1 christos
306 1.1 christos echo 1 >foo1
307 1.1 christos $awk ' { exit }
308 1.1 christos END { print NR }' /etc/passwd >foo2
309 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit'
310 1.1 christos
311 1.1 christos echo 1 >foo1
312 1.1 christos $awk ' {i = 1; while (i <= NF) {if (i == NF) exit; i++ } }
313 1.1 christos END { print NR }' /etc/passwd >foo2
314 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 2'
315 1.1 christos
316 1.1 christos echo 1 >foo1
317 1.1 christos $awk ' function f() {
318 1.1 christos i = 1; while (i <= NF) {if (i == NF) return NR; i++ }
319 1.1 christos }
320 1.1 christos { if (f() == 1) exit }
321 1.1 christos END { print NR }' /etc/passwd >foo2
322 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc while return'
323 1.1 christos
324 1.1 christos echo 1 >foo1
325 1.1 christos $awk ' function f() {
326 1.1 christos split("a b c", arr)
327 1.1 christos for (i in arr) {if (i == 3) return NR; i++ }
328 1.1 christos }
329 1.1 christos { if (f() == 1) exit }
330 1.1 christos END { print NR }' /etc/passwd >foo2
331 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc while return'
332 1.1 christos
333 1.1 christos echo 1 >foo1
334 1.1 christos $awk ' {i = 1; do { if (i == NF) exit; i++ } while (i <= NF) }
335 1.1 christos END { print NR }' /etc/passwd >foo2
336 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 3'
337 1.1 christos
338 1.1 christos echo 1 >foo1
339 1.1 christos $awk ' function f() {
340 1.1 christos i = 1; do { if (i == NF) return NR; i++ } while (i <= NF)
341 1.1 christos }
342 1.1 christos { if (f() == 1) exit }
343 1.1 christos END { print NR }' /etc/passwd >foo2
344 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc do return'
345 1.1 christos
346 1.1 christos echo 1 >foo1
347 1.1 christos $awk ' {i = 1; do { if (i == NF) break; i++ } while (i <= NF); exit }
348 1.1 christos END { print NR }' /etc/passwd >foo2
349 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 4'
350 1.1 christos
351 1.1 christos echo 1 >foo1
352 1.1 christos $awk ' { n = split($0, x)
353 1.1 christos for (i in x) {
354 1.1 christos if (i == 1)
355 1.1 christos exit } }
356 1.1 christos END { print NR }' /etc/passwd >foo2
357 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc immmediate exit 5'
358 1.1 christos
359 1.1 christos echo XXXXXXXX >foo1
360 1.1 christos $awk 'BEGIN { s = "ab\fc\rd\be"
361 1.1 christos t = s; gsub("[" s "]", "X", t); print t }' >foo2
362 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc weird escapes in char class'
363 1.1 christos
364 1.1 christos $awk '{}' /etc/passwd glop/glop >foo 2>foo2
365 1.1 christos grep "can't open.*glop" foo2 >/dev/null || echo "BAD: T.misc can't open"
366 1.1 christos
367 1.1 christos echo '
368 1.1 christos
369 1.1 christos
370 1.1 christos a
371 1.1 christos aa
372 1.1 christos
373 1.1 christos b
374 1.1 christos
375 1.1 christos
376 1.1 christos c
377 1.1 christos
378 1.1 christos ' >foo
379 1.1 christos echo 3 >foo1
380 1.1 christos $awk 'BEGIN { RS = "" }; END { print NR }' foo >foo2
381 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc RS botch'
382 1.1 christos
383 1.1 christos $awk 'BEGIN \
384 1.1 christos {
385 1.1 christos print "hello, world"
386 1.1 christos }
387 1.1 christos }}}' >foo1 2>foo2
388 1.1 christos grep 'source line 4' foo2 >/dev/null 2>&1 || echo 'BAD: T.misc continuation line number'
389 1.1 christos
390 1.1 christos
391 1.1 christos echo 111 222 333 >foo
392 1.1 christos $awk '{ f[1]=1; f[2]=2; print $f[1], $f[1]++, $f[2], f[1], f[2] }' foo >foo2
393 1.1 christos echo 111 111 222 2 2 >foo1
394 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc $f[1]++'
395 1.1 christos
396 1.1 christos
397 1.1 christos # These should be syntax errors
398 1.1 christos $awk . 2>foo
399 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error . fails"
400 1.1 christos
401 1.1 christos $awk .. 2>foo
402 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .. fails"
403 1.1 christos
404 1.1 christos $awk .E. 2>foo
405 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .E. fails"
406 1.1 christos
407 1.1 christos $awk .++. 2>foo
408 1.1 christos grep "syntax error" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error .++. fails"
409 1.1 christos
410 1.1 christos
411 1.1 christos
412 1.1 christos # These should be syntax errors
413 1.1 christos $awk '$' 2>foo
414 1.1 christos grep "unexpected" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error $ fails"
415 1.1 christos
416 1.1 christos $awk '{print $' 2>foo
417 1.1 christos grep "unexpected" foo >/dev/null || echo 1>&2 "BAD: T.misc syntax error $2 fails"
418 1.1 christos
419 1.1 christos $awk '"' 2>foo
420 1.1 christos grep "non-terminated" foo >/dev/null || echo 1>&2 "BAD: T.misc bare quote fails"
421 1.1 christos
422 1.1 christos
423 1.1 christos # %c of 0 is explicit null byte
424 1.1 christos
425 1.1 christos ./echo '3' >foo1
426 1.1 christos $awk 'BEGIN {printf("%c%c\n", 0, 0) }' | wc | $awk '{print $3}' >foo2
427 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc null byte'
428 1.1 christos
429 1.1 christos # non-terminated RE
430 1.1 christos
431 1.1 christos $awk /xyz >foo 2>&1
432 1.1 christos grep "non-terminated" foo >/dev/null || echo 1>&2 "BAD: T.misc non-terminated RE"
433 1.1 christos
434 1.1 christos # next several were infinite loops, found by brian tsang.
435 1.1 christos # this is his example:
436 1.1 christos
437 1.1 christos $awk 'BEGIN {
438 1.1 christos switch (substr("x",1,1)) {
439 1.1 christos case /ask.com/:
440 1.1 christos break
441 1.1 christos case "google":
442 1.1 christos break
443 1.1 christos }
444 1.1 christos }' >foo 2>&1
445 1.1 christos grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 1"
446 1.1 christos
447 1.1 christos $awk 'BEGIN { s { c /./ } }' >foo 2>&1
448 1.1 christos grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 2"
449 1.1 christos
450 1.1 christos $awk 'BEGIN { s { c /../ } }' >foo 2>&1
451 1.1 christos grep "illegal statement" foo >/dev/null || echo 1>&2 "BAD: T.misc looping syntax error 3"
452 1.1 christos
453 1.1 christos $awk 'BEGIN {printf "%2$s %1$s\n", "a", "b"}' >foo 2>&1
454 1.1 christos grep "'$' not permitted in awk formats" foo >/dev/null || echo 1>&2 "BAD: T.misc '$' not permitted in formats"
455 1.1 christos
456 1.1 christos echo 'a
457 1.1 christos b c
458 1.1 christos de fg hi' >foo0
459 1.1 christos $awk 'END { print NF, $0 }' foo0 >foo1
460 1.1 christos awk '{ print NF, $0 }' foo0| tail -1 >foo2
461 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0'
462 1.1 christos
463 1.1 christos echo 'fg hi' >foo0
464 1.1 christos $awk 'END { print NF, $0 }' foo0 >foo1
465 1.1 christos awk '{ print NF, $0 }' foo0| tail -1 >foo2
466 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0'
467 1.1 christos
468 1.1 christos echo '' >foo0
469 1.1 christos $awk 'END { print NF, $0 }' foo0 >foo1
470 1.1 christos awk '{ print NF, $0 }' foo0| tail -1 >foo2
471 1.1 christos cmp -s foo1 foo2 || echo 'BAD: T.misc END must preserve $0'
472 1.1 christos
473 1.1 christos # Check for nonzero exit status on I/O error.
474 echo 'E 2' >foo1
475 (trap '' PIPE; "$awk" 'BEGIN { print "hi"; }' 2>/dev/null; echo "E $?" >foo2) | :
476 cmp -s foo1 foo2 || echo 'BAD: T.misc exit status on I/O error'
477