# Making a New Command Version

This section explains the steps you'll use to make a new MH command version. Some of the steps need to be done only once before making the first new command version.

For example, you can make a new version of the scan command called tscan. After this, if you type the command scan, it will work the way it always has. But if you use tscan, it will automatically use the -form scan.timely switch to show the date in a different style, as shown in the following example:

        % scan 3-5

           3  02/04*To:vicki@maxa.nap  Problems with maxa<<Vicki, I thi
           4  12/14 To:uunet!xyz!pamb  Holiday Greetings<<Pam, I just w
           5  04/06 mary@hahvahd.edu   rcvtty -- how do I use it?<<I've
        % tscan 3-5
           3   Sun *To:vicki@maxa.nap  Problems with maxa<<Vicki, I thi
           4  14Dec To:uunet!xyz!pamb  Holiday Greetings<<Pam, I just w
           5  Apr92 mary@hahvahd.edu   rcvtty -- how do I use it?<<I've

Let's start with a summary of the steps. Do these steps only once before making the first version (the Section Setup Before You Make First New Version explains how to do that):

1. Make a bin directory if you need one.
2. Choose the best way to make new versions on your host.

Do these steps for making each new version (see the Section What to Do for Each New Version):

1. Pick a new name for the version. Be sure it's not already in use.
2. Add an entry for the version to your MH profile.
3. Find the pathname of the MH command you're making a version of.
4. Make the version, the way it was chosen in the Section Setup Before You Make First New Version.
5. If you use the C shell, run its rehash command.

The Chapter Key Parts of the UNIX Filesystem will help, too.

## Setup Before You Make First New Version

This section has overall setup that you'll only need to do once.

Making a bin Directory, Setting Search Path

You need a place to put your new MH programs. This can be a directory on your account. Or, if several people want to use these programs, you could pick any other directory -- as long as you have write access to it. Usually, the directory's name is something like bin. Here are the steps:

1. If you haven't set up a directory for programs, make one. For instance, to make a bin under your home directory, type:

             % cd
             % mkdir bin

2. If you have the directory for storing programs, be sure that the programs in it are accessible. Type the command `echo $PATH` and look for the directory's pathname. For instance, if your directory is called /u/walt/bin, you should see:

             % echo $PATH
             ...:/u/walt/bin:...

   If the directory isn't in your PATH, add it. Do that by editing the `PATH=...` line in your .profile file or the `set path=(...)` line in your .cshrc or .login file. Add the full pathname of the directory to the end of the PATH. Then, for the Bourne and Korn shells, type the command:

             $ . .profile

   For the C shell, type one of these commands, depending on which file you changed:

             % source .cshrc
             % source .login

   Finally, if other people are sharing the directory, use a command like chmod go+rx bin to give them access.

Finding the Best Way to Make New Versions

The first time you make a new command version, you'll need to figure out how to do it on your particular account and computer. There are a few different ways. Here's how to decide which one is best for you:

1. If your version of UNIX has symbolic links, this is usually the easiest way. (If you aren't sure, type `man ln` and look for the -s option.) Some people call these soft links.

   For example, to make the version of scan called tscan, you first find where the scan program is stored. (There are instructions for doing that below.) Then, you cd to your bin directory and type commands like:

             % ln -s /usr/local/mh/scan tscan
             % ls -l tscan
             lrwxrwxrwx  1 eds       16 Jul  1 14:32 tscan -> /usr/local/mh/scan
             % ls -lL tscan
             -rwxr-xr-x  1 root   81920 May 26 19:04 tscan

   The `ls -l` command shows the link itself and the `ls -lL` command shows the file that the link "points to."

   There's one thing to watch out for: each symbolic link takes a block of disk space. If you're short on disk space and you plan to make a lot of symbolic links, you may want to use one of the three other methods below.

2. If you won't be using symbolic links, you may be able to use standard links (I'll call them hard links). These are the same kind of links that MH makes between linked messages.

   Hard links are good because they take virtually no filesystem space. But they won't work if the programs you want to link to are on a different filesystem. (If you're not sure whether the program is on a different filesystem, try to make the link and see if it works, or ask a local expert.)

   Another problem with hard links can happen when the system administrator installs a new version of the program you're linked to. Unless the administrator is careful, you could end up with a link to the old version of the program, instead of the new one! (There's one workaround here: the system administrator could make a system directory and put the hard links there for everyone on the system to use.) The bottom line: if you want to make hard links, talk to your system administrator.

   Here's how to make a hard link. For example, to make the version of scan called tscan, you'd first find where the scan program is stored. Then, you'd cd to your bin directory and type commands like:

             % ln /usr/local/mh/scan tscan
             % ls -li /usr/local/mh/scan tscan
             13256 -rwxr-xr-x  2 root  81920  May 26 19:04 /usr/local/mh/scan
             13256 -rwxr-xr-x  2 root  81920  May 26 19:04 tscan

   If you make hard links, it's a good idea to use ls -li every so often, to compare the original program with your link. If the two listings are different (except for the names), your link to the system version was broken.
3. If symbolic links and hard links don't appeal to you, a small program called execit, written in the C language, might be what you want. execit will run an MH command under any name you choose. If your UNIX system has a C compiler (usually named cc or gcc), that and the ln command are all you need to use execit.

   To set up execit, edit a simple table of renamed commands in a file called execit.include. Then compile the execit.c file with one command. Finally, run a shell script named execit.link to make the links for you:

             % vi execit.include
                 ...Add a line for tscan to the table...
             % cc -o execit execit.c
             % execit.link

   The execit.link script makes as many hard links to the execit program as you need, one link per version. If you're making many command versions, this can save disk space as compared to symbolic links.

## What to Do for Each New Version

After you've done the first-time setup in the Section Setup Before You Make First New Version (which you only need to do once), you're ready for this section. Here are the overall steps to do each time you make a new version of an MH command:

1. Pick a new name for your MH version. For instance, you might call it tscan. Make sure that it doesn't conflict with any other commands on the system by typing one of the commands in the following example. If you get output (besides an error) from one of them, there's probably already a command with the same name. (The whence command works on the Korn shell; I've shown it with the ksh dollar sign (`$`) prompt.)

             % man 1 tscan
             No manual entry for tscan in section 1.
             % which tscan
             no tscan in . /xxx/ehuser/bin /usr/bin/X11 /usr/local/bin ...
             % whereis tscan
             tscan:

             $ whence tscan

2. Once you find an unused name, add an entry for the command to your MH profile. The entry starts with the name of your command, then has a colon, and finally shows the command-line switches you want to use with the program. For instance, the entry for tscan could be:

             tscan: -form scan.timely

   Be sure not to leave any blank lines in the file.
3. Find out where the actual MH command is located by typing each of the following commands until you get an answer:

             % which scan
             % whereis scan
             $ whence scan

   The answer should be a pathname, something like /usr/local/mh/scan.

   If you still can't find it, type `ls` in the MH binary directory or ask an expert for help.

4. Make the symbolic link or hard link or use execit as explained in the Section Setup Before You Make First New Version.
5. If you're using the C shell, type the following command to reset the shell's command search table:

             % rehash

That's it. Try your new version. If you want to change the switches you chose, you just need to edit your MH profile. If you get an error such as the following:

        tscan: command not found

there's a problem with your shell's search path, your link, or your execit.include file. Reread these instructions carefully -- if that doesn't help, it's time to get your guru. Once you get the hang of these steps, it only takes a minute to add a new command version.