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