Writing Command Versions as Aliases or Functions

[previous] [next] [table of contents] [index]

As you saw in the Section They Won't Always Work, aliases and shell functions can't be used everywhere that command versions can. Sometimes, though -- especially for commands that you'll never use from anywhere except a shell prompt -- an alias or function is all you really need.

To write a command version from this chapter as an alias or function:

  1. Use the version name (like tscan) as the name of the alias.
  2. Use the MH command name (like scan) as the command run by the alias.
  3. Put the MH profile arguments after the MH command.
As an example, the tscan command version from the Section Making a New Command Version would become this C shell alias:
alias tscan 'scan -form scan.timely'
When you run a C shell alias, the shell will use any arguments you type after the alias name as arguments to the command in the alias. What I mean is, if you use the tscan alias above and type:
% tscan +reports last:20
the shell will run:
scan -form scan.timely +reports last:20
That alias trick will work with all the command versions in this chapter that can be done as an alias. When you write a shell function, though, you need to include the arguments with $*. Here's tscan as a Bourne shell function:
tscan()
{
scan -form scan.timely $*
}
Most command versions in this chapter can be written as an alias or function. The prompter version in the Section Append Text with prompter.nopre and the send version in the Section Version of send: push can't because they're run directly by other MH commands.

[Table of Contents] [Index] [Previous: Making a New Command Version] [Next: Versions of repl]


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

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>

Questions or problems regarding this web site should be directed to Steve Gielda.
Copyright 1999 www.cotse.com.  All rights reserved.
Last modified: Friday April 02, 1999.