[comp.unix.ultrix] Ultrix 4.1 awk substr/split bug

D. Allen [CGL]" <idallen@watcgl.waterloo.edu> (02/08/91)

#!/bin/sh
# This shows that substr and split interact in a bad way on Ultrix.
# This appears in every version of Ultrix I have tried here, including
# the very latest Ultrix 4.1 (RISC).
# (Same bug shows up on several O/S, including 4.3 BSD.)
# idallen@watcgl.waterloo.edu
#
exec awk '
BEGIN {
	s = "xxxxxxxxxarg1 arg2"

	print "substring is", substr(s,10,20)
	n = split(substr(s,10,20),x," ")
	print "n is", n
	print "x[1] is", x[1]
	print "x[2] is", x[2]

	t = substr(s,10,20)
	n = split(t,x," ")
	print "n is", n
	print "x[1] is", x[1]
	print "x[2] is", x[2]
}' </dev/null

Output:

    substring is arg1 arg2
    n is 2
    x[1] is arg1 arg2            <== wrong
    x[2] is arg2
    n is 2
    x[1] is arg1                 <== right
    x[2] is arg2
-- 
-IAN! (Ian! D. Allen) idallen@watcgl.uwaterloo.ca idallen@watcgl.waterloo.edu
 [129.97.128.64]  Computer Graphics Lab/University of Waterloo/Ontario/Canada