MH & nmh: Email for Users & Programmers

May, 2006

Writing Command Versions as Aliases or Functions

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:
        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.