From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: Octal chmod status
Originator: tchrist@pixel.convex.com
Date: Wed, 19 Aug 1992 13:05:58 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: CONVEX Realtime Development, Colorado Springs, CO
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of mju@mudos.ann-arbor.mi.us (Marc Unangst):
:In article <1992Aug18.181609.8988@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
:>You might, and people might even use it if they want to lug
:>another huge a.out and overly large and misplaceable foo.c 
:>around with them wherever they go.  I'd just use this:
:>
:>    perl -e 'printf("%04o\n", (stat($ARGV[0]))[2] & 07777)'
:
:Hmm.  Huge a.out, huh?  Overly large foo.c, huh?  Hmm.
:
:mju@mudos:~$ ls -l getperms getperms.c
:-rwxr-xr-x   1 mju      group       4780 Aug 19 01:06 getperms
:-rw-r--r--   1 mju      group        445 Aug 15 01:08 getperms.c
:mju@mudos:~$ cd /usr/local/bin
:mju@mudos:/usr/local/bin$ ls -l perl*
:lrwxrwxrwx   1 root     other          9 Aug 19 01:07 perl -> perl4.019
:-rwxr-xr-x   1 bin      bin       283992 Aug 19 01:06 perl4.019
:mju@mudos:/usr/local/bin$ cd ../src
:mju@mudos:/usr/local/src$ ls -l perl-4.019.tar.Z
:-rw-r--r--   1 mju      mju       801616 Aug 10 13:04 perl-4.019.tar.Z
:mju@mudos:/usr/local/src$ exit
:
:Sure looks like my program is smaller.  Could just be an optical
:illusion, though...

It is.  You're confused.

    % ls -l getperms*
      60 -rwxr-xr-x  1 tchrist     60785 Aug 19 07:48 getperms
       2 -rw-r--r--  1 tchrist       452 Aug 19 07:48 getperms.c
       2 -rw-r--r--  1 tchrist        42 Aug 19 07:49 getperms.pl

You may only include the size of the perl compiler if you 
include the size of the C compiler.  You may only include
the size of the perl libraries if you include the size of
the perl libraries.

I suspect that you neglected to include the shared libraries
that your a.out would have sucked in.  

Notice that you KNOW perl is the right answer here because of
the mystical significance of its program's length.

It took me mere seconds to write the perl solution.  It requires
no separate a.out and source code, and can be easily embedded in 
a shell script if you want.  How long does it take you to write
the C code, compile it for every single architecture on which it
might run, then copy the binary around to every machine you want
to run it on?  

    % time perl getperms.pl .
    0.008u 0.043s 0:00.03 50.0% 0+0k 0+0io 53pf+0w

    % time getperms .
    0.001u 0.028s 0:00.02 50.0% 0+0k 0+0io 11pf+0w

Sure, the C solution does run faster: one one-hundredth of a second
faster.  Big deal.  That infinitesimal time difference is surely not
worth all the hassle of writing a C program for each and every little
dohickey you need to whip up that's too inconvenient or inefficient to
use the shell for.  If we all did that, we'd have 100 little special
purpose binaries sitting around instead of using sed, awk, or perl, 
and carrying our scripts, no longer self-conftained, around to wherever
we needed them would be a major pain.

--tom

-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

Besides, it's good to force C programmers to use the toolbox occasionally. :-)
        --Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
Newsgroups: comp.unix.shell