4.2BSD awk bugs (was Re: Using pipes within awk programs)

Dave Lennert davel at hpcupt1.HP.COM
Sun Jan 31 15:20:27 AEST 1988


> In article <515 at root44.co.uk> you write:
> >	who | awk '{ print $1 | "sort" }'
> >gives the same output as
> >	who | awk '{ print $1 }' | sort
> 
> FYI, the two *don't* give the same results under Ultrix T2.0-1I.

One explanation could be that early versions of awk (e.g., 4.2) do
not wait for all their children to finish before exiting.  So, in
the first example above, the awk could finish while the sort is running.

If stdout is a terminal and BSD job control is active and the LTOSTOP
flag is set, then you won't see any (or complete) output since the
sort will be killed when it attempts output as a background, orphaned
process.

If stdout is a file, then the user (or the next command in the script)
could examine the file before it is completely written by sort.

Now you know why all my scripts look like:

	who | awk '{ print $1 | "sort" }' > tmp
	sleep 60	# hack for awk
	cat tmp

-Dave Lennert   HP    ihnp4!hplabs!hpda!davel



More information about the Comp.unix.questions mailing list