What's wrong with this Bourne shell script?

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Sun Aug 12 04:55:52 AEST 1990


In article <850 at jonlab.UUCP> jon at jonlab.UUCP (Jon H. LaBadie) writes:
: In article <1990Aug6.172225.20319 at iwarp.intel.com>, merlyn at iwarp.intel.com (Randal Schwartz) writes:
: > In article <1990Aug3.193231.3166 at silma.com>, aab at silma (Andy Burgess) writes:
: > | While you're at it, is there a better way to get the total bytes
: > | of the files in a directory?
: > 
: >    PERL SCRIPT DELETED
: 
: A script of mine called "addcol" was printed in UNIX World's monthly
: column Wizard's Grabbag and would do the same thing without perl;
: 
: 	ls -ld | addcol -4
: 
: However, have we forgotten our roots?  I'm surprised in this thread
: that no one has mentioned:
: 
: 	TOTAL=`cat * | wc -c`

Let us be explicit about the advantages and disadvantages of these
approaches.  Any naive approach using ls is gonna screw up in /dev,
and probably does the opposite of what you want on symbolic links.
The cat approach has to read all the bytes (try it on a swapfile), but
probably does what you want on symbolic links.  It may or may not do
what you want on files with holes in them.  It doesn't do what you want
with the last access times.  It CERTAINLY doesn't do what you want in /dev,
or in a directory containing a FIFO or a Unix domain socket.

The stat structure in C is quite straightforward by comparison.  Pity
there's such a big ecological niche between shell and C...

Larry



More information about the Comp.unix.questions mailing list