Path: utzoo!utgpu!watmath!clyde!att!pacbell!ames!ncar!tank!nic.MR.NET!stolaf!mike From: mike@stolaf.UUCP (Mike Haertel) Newsgroups: comp.unix.wizards Subject: Re: cat -u Keywords: cruft Message-ID: <783@stolaf.UUCP> Date: 29 Nov 88 02:32:08 GMT References: <175@ernie.NECAM.COM> <189@wyn386.UUCP> <8910@smoke.BRL.MIL> <118@hudson.Morgan.COM> <8941@smoke.BRL.MIL> <480@auspex.UUCP> <8956@smoke.BRL.MIL> <730@quintus.UUCP> <8973@smoke.BRL.MIL> <748@quintus.UUCP> <8985@smoke.BRL.MIL> <4864@bsu-cs.UUCP> Reply-To: mike@wheaties.ai.mit.edu Distribution: na Organization: St. Olaf College, Northfield, MN Lines: 43 In article <4864@bsu-cs.UUCP> dhesi@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:!{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@wheaties.ai.mit.edu In Hell they run VMS.