cat -u

Mike Haertel mike at stolaf.UUCP
Tue Nov 29 12:32:08 AEST 1988


In article <4864 at bsu-cs.UUCP> dhesi at bsu-cs.UUCP (Rahul Dhesi) writes:
>Well, now, it might be cruft, but -u is *useful* cruft.  I have a shell
>script containing the line:
>
>     /bin/cat -uv "$file" | /usr/ucb/more -10d
>
>I couldn't get it to work right without the -u option.
>-- 
>Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee}!bsu-cs!dhesi

As far as I know, -u basically means

	while ((count = read(fd, buf, sizeof buf)) > 0)
		write(1, buf, count);
	
as opposed to using fread and buffered stdio.  This makes a difference
when copying between devices that don't necessarily return as many
bytes as you asked for in read (e.g., ttys).  For example, consider the
following cheapo write(1):
	
	$ cat > /dev/somebody_elses_tty

With raw I/O it works as expected, with fread it doesn't.  If your
loop is

	while ((c = getchar()) != EOF)
		putchar(c);

then it works as expected, at least on the machines I have used.

I believe (somebody at Bell Labs correct me, maybe?) that -u was added
in going from version 6 to version 7 when cat was rewritten from using
assembly language and something equivalent to getchar() to C and fread.

And of course, the existence of one flag (-u) was too much for the
alphabet soup people to resist, so we get REAL cruft like -v, -s
(which means different things on BSD and Sys V!) and all that . . .

The cat I use (one I wrote myself) doesn't take any switches.
It's also faster.
-- 
Mike Haertel					mike at wheaties.ai.mit.edu
			In Hell they run VMS.



More information about the Comp.unix.wizards mailing list