xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/fflush.sh (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
1#! /bin/sh
2
3if [ -z "$AWK" ]; then
4    printf '$AWK must be set\n' >&2
5    exit 1
6fi
7
8$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"cat"}'
9
10$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"cat"}'|cat
11
12# gawk and nawk differ here: nawk will close stdout, and future writes (by nawk
13# or by the cat child) will fail. gawk's child will print "2nd" here, and also
14# allow other print statements to succeed.
15$AWK 'BEGIN{print "1st";fflush("/dev/stdout");close("/dev/stdout");print "2nd"|"cat"}'|cat
16
17$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"cat";close("cat")}'|cat
18
19$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"cat";close("cat")}'|cat
20
21$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"cat";close("cat")}'|cat
22
23$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"sort"}'|cat
24
25$AWK 'BEGIN{print "1st";fflush("/dev/stdout");print "2nd"|"sort";close("sort")}'|cat
26