What Good is a File With 1000 Links?

[return-to: Finding Program Name; Multiple Program Names] [table of contents] [index]

You can take linking to extremes in a useful way by the following short shell script named README. It's also named 1, 2, 3... and 999. In fact, it has 1000 links (though it could have more or fewer):

#! /bin/sh
# This shell script has lots of hard links, and all of them are
# to this file.  When you run this program, it shows the MH
# mail message with its name.  For instance, if you type:
#   % 5
# this program will execute the command 'show 5'.
/usr/local/mh/show `basename $0` $*
I put that short file in a directory named shows. My friends and I put the shows directory in our shell search paths (the Section Setup Before You Make First New Version explains how). Then I made the README file executable and made 999 hard links to it with the C shell loop below. The @ is the C shell's arithmetic operator:
% chmod +x README
% @ num=1
% while ($num < 1000)
? ln README $num
? echo made link $num
? @ num++
? end
made link 1
    ...
made link 999
This lets me read an MH message just by typing the message number. In fact, the $* in the script lets me give arguments to the show command. The following line will show messages 3, 12, and 22:
% 3 12 22
(That executes show 3 12 22.) Folders like +inbox work, too.

Actually, to make this more efficient, I used the shell's exec command:

exec /usr/local/mh/show `basename $0` $*
The exec saves a process (this is described with the resend.fixmsg script.

Check with your system administrator before you do this; it is unusual to have thousands of links. Some filesystem-handling programs might not be robust enough to cope.

[Table of Contents] [Index] [Return to: Finding Program Name; Multiple Program Names]


Last change $Date: 1996/06/06 15:15:02 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jerry@ora.com>

HIVE: All information for read only. Please respect copyright!
Hosted by hive КГБ: Киевская городская библиотека