1*3ee4fc2aSCody Peter Mello#!/bin/bash 2*3ee4fc2aSCody Peter Mello 3*3ee4fc2aSCody Peter Melloif [[ -z "$AWK" || -z "$WORKDIR" ]]; then 4*3ee4fc2aSCody Peter Mello printf '$AWK and $WORKDIR must be set\n' >&2 5*3ee4fc2aSCody Peter Mello exit 1 6*3ee4fc2aSCody Peter Mellofi 7*3ee4fc2aSCody Peter Mello 8*3ee4fc2aSCody Peter MelloTEMP0=$WORKDIR/test.temp.0 9*3ee4fc2aSCody Peter MelloTEMP1=$WORKDIR/test.temp.1 10*3ee4fc2aSCody Peter Mello 11*3ee4fc2aSCody Peter MelloRESULT=0 12*3ee4fc2aSCody Peter Mello 13*3ee4fc2aSCody Peter Mellofail() { 14*3ee4fc2aSCody Peter Mello echo "$1" >&2 15*3ee4fc2aSCody Peter Mello RESULT=1 16*3ee4fc2aSCody Peter Mello} 17*3ee4fc2aSCody Peter Mello 18*3ee4fc2aSCody Peter Melloecho T.nextfile: tests of nextfile command 19*3ee4fc2aSCody Peter Mello 20*3ee4fc2aSCody Peter Mello# 1st lines of some files 21*3ee4fc2aSCody Peter Mellorm -f $TEMP0 22*3ee4fc2aSCody Peter Mellofor i in T.* 23*3ee4fc2aSCody Peter Mellodo 24*3ee4fc2aSCody Peter Mello sed 1q $i >> $TEMP0 25*3ee4fc2aSCody Peter Mellodone 26*3ee4fc2aSCody Peter Mello 27*3ee4fc2aSCody Peter Mello$AWK ' 28*3ee4fc2aSCody Peter Mello{ print $0; nextfile } # print first line, quit 29*3ee4fc2aSCody Peter Mello' T.* > $TEMP1 30*3ee4fc2aSCody Peter Mello 31*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 1' 32*3ee4fc2aSCody Peter Mello 33*3ee4fc2aSCody Peter Mello$AWK ' # same test but in a for loop 34*3ee4fc2aSCody Peter Mello{ print $0; 35*3ee4fc2aSCody Peter Mello for (i = 1; i < 10; i++) 36*3ee4fc2aSCody Peter Mello if (i == 1) 37*3ee4fc2aSCody Peter Mello nextfile 38*3ee4fc2aSCody Peter Mello print "nextfile for error" 39*3ee4fc2aSCody Peter Mello} # print first line, quit 40*3ee4fc2aSCody Peter Mello' T.* > $TEMP1 41*3ee4fc2aSCody Peter Mello 42*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 1f' 43*3ee4fc2aSCody Peter Mello 44*3ee4fc2aSCody Peter Mello$AWK ' # same test but in a while loop 45*3ee4fc2aSCody Peter Mello{ print $0; 46*3ee4fc2aSCody Peter Mello i = 1 47*3ee4fc2aSCody Peter Mello while (i < 10) 48*3ee4fc2aSCody Peter Mello if (i++ == 1) 49*3ee4fc2aSCody Peter Mello nextfile 50*3ee4fc2aSCody Peter Mello print "nextfile while error" 51*3ee4fc2aSCody Peter Mello} # print first line, quit 52*3ee4fc2aSCody Peter Mello' T.* > $TEMP1 53*3ee4fc2aSCody Peter Mello 54*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 1w' 55*3ee4fc2aSCody Peter Mello 56*3ee4fc2aSCody Peter Mello$AWK ' # same test but in a do loop 57*3ee4fc2aSCody Peter Mello{ print $0; 58*3ee4fc2aSCody Peter Mello i = 1 59*3ee4fc2aSCody Peter Mello do { 60*3ee4fc2aSCody Peter Mello if (i++ == 1) 61*3ee4fc2aSCody Peter Mello nextfile # print first line, quit 62*3ee4fc2aSCody Peter Mello } while (i < 10) 63*3ee4fc2aSCody Peter Mello print "nextfile do error" 64*3ee4fc2aSCody Peter Mello} 65*3ee4fc2aSCody Peter Mello' T.* > $TEMP1 66*3ee4fc2aSCody Peter Mello 67*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 1d' 68*3ee4fc2aSCody Peter Mello 69*3ee4fc2aSCody Peter Mello 70*3ee4fc2aSCody Peter Mello# 100 lines of some files 71*3ee4fc2aSCody Peter Mellorm -f $TEMP0 72*3ee4fc2aSCody Peter Mellofor i in T.* 73*3ee4fc2aSCody Peter Mellodo 74*3ee4fc2aSCody Peter Mello sed 100q $i >> $TEMP0 75*3ee4fc2aSCody Peter Mellodone 76*3ee4fc2aSCody Peter Mello 77*3ee4fc2aSCody Peter Mello$AWK ' 78*3ee4fc2aSCody Peter Mello{ print } 79*3ee4fc2aSCody Peter MelloFNR == 100 { nextfile } # print first line, quit 80*3ee4fc2aSCody Peter Mello' T.* > $TEMP1 81*3ee4fc2aSCody Peter Mello 82*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 2' 83*3ee4fc2aSCody Peter Mello 84*3ee4fc2aSCody Peter Mello 85*3ee4fc2aSCody Peter Mello> $TEMP0 # empty 86*3ee4fc2aSCody Peter Mello$AWK ' { nextfile; print $0 }' T.* > $TEMP1 87*3ee4fc2aSCody Peter Mello 88*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 3' 89*3ee4fc2aSCody Peter Mello 90*3ee4fc2aSCody Peter Mello# skip weird args 91*3ee4fc2aSCody Peter Mellorm -f $TEMP0 92*3ee4fc2aSCody Peter Mellofor i in T.* 93*3ee4fc2aSCody Peter Mellodo 94*3ee4fc2aSCody Peter Mello sed 1q $i >> $TEMP0 95*3ee4fc2aSCody Peter Mellodone 96*3ee4fc2aSCody Peter Mello 97*3ee4fc2aSCody Peter Mello$AWK ' 98*3ee4fc2aSCody Peter Mello{ print $0; nextfile } # print first line, quit 99*3ee4fc2aSCody Peter Mello' T.* > $TEMP1 100*3ee4fc2aSCody Peter Mello 101*3ee4fc2aSCody Peter Mellodiff $TEMP0 $TEMP1 || fail 'BAD: T.nextfile 4' 102*3ee4fc2aSCody Peter Mello 103*3ee4fc2aSCody Peter Melloexit $RESULT 104