1335640Shselaskyecho T.getline: test getline function 2335640Shselasky 3335640Shselaskyawk=${awk-../a.out} 4335640Shselasky 5335640Shselaskywho >foo1 6335640Shselaskycat foo1 | $awk ' 7335640ShselaskyBEGIN { 8335640Shselasky while (getline) 9335640Shselasky print 10335640Shselasky exit 11335640Shselasky} 12335640Shselasky' >foo 13335640Shselaskycmp -s foo1 foo || echo 'BAD: T.getline (bare getline)' 14335640Shselasky 15335640Shselaskywho >foo1 16335640Shselaskycat foo1 | $awk ' 17335640ShselaskyBEGIN { 18335640Shselasky while (getline xxx) 19335640Shselasky print xxx 20335640Shselasky exit 21335640Shselasky} 22335640Shselasky' >foo 23335640Shselaskycmp -s foo1 foo || echo 'BAD: T.getline (getline xxx)' 24335640Shselasky 25335640Shselasky$awk ' 26335640ShselaskyBEGIN { 27335640Shselasky while (getline <"/etc/passwd") 28335640Shselasky print 29335640Shselasky exit 30335640Shselasky} 31335640Shselasky' >foo 32335640Shselaskycmp -s /etc/passwd foo || echo 'BAD: T.getline (getline <file)' 33335640Shselasky 34335640Shselaskycat /etc/passwd | $awk ' 35335640ShselaskyBEGIN { 36335640Shselasky while (getline <"-") # stdin 37335640Shselasky print 38335640Shselasky exit 39335640Shselasky} 40335640Shselasky' >foo 41335640Shselaskycmp -s /etc/passwd foo || echo 'BAD: T.getline (getline <"-")' 42335640Shselasky 43335640Shselasky$awk ' 44335640ShselaskyBEGIN { 45 while (getline <ARGV[1]) 46 print 47 exit 48} 49' /etc/passwd >foo 50cmp -s /etc/passwd foo || echo 'BAD: T.getline (getline <arg)' 51 52$awk ' 53BEGIN { 54 while (getline x <ARGV[1]) 55 print x 56 exit 57} 58' /etc/passwd >foo 59cmp -s /etc/passwd foo || echo 'BAD: T.getline (getline x <arg)' 60 61$awk ' 62BEGIN { 63 while (("cat " ARGV[1]) | getline) 64 print 65 exit 66} 67' /etc/passwd >foo 68cmp -s /etc/passwd foo || echo 'BAD: T.getline (cat arg | getline)' 69 70$awk ' 71BEGIN { 72 while (("cat " ARGV[1]) | getline x) 73 print x 74 exit 75} 76' /etc/passwd >foo 77cmp -s /etc/passwd foo || echo 'BAD: T.getline (cat arg | getline x)' 78 79$awk ' BEGIN { print getline <"/glop/glop/glop" } ' >foo 80echo '-1' >foo1 81cmp -s foo foo1 || echo 'BAD: T.getline (non-existent file)' 82 83echo 'false false equal' >foo1 84$awk 'BEGIN { 85 "echo 0" | getline 86 if ($0) printf "true " 87 else printf "false " 88 if ($1) printf "true " 89 else printf "false " 90 if ($0==$1) printf "equal\n" 91 else printf "not equal\n" 92}' >foo2 93cmp -s foo1 foo2 || echo 1>&2 'BAD: T.getline bad $0 type in cmd|getline' 94 95echo 'L1 96L2' | $awk 'BEGIN { $0="old stuff"; $1="new"; getline x; print}' >foo1 97echo 'new stuff' >foo2 98cmp -s foo1 foo2 || echo 1>&2 'BAD: T.getline bad update $0' 99