Columbia MM
MM Manual


One of the characteristics of UNIX is that processes (commands and programs) can pass data to each other, an operation known as piping. MM has a few features to pipe text between messages and external (non-MM) commands as standard input and output.


You might want to redirect the output of a command into a message, so you can include the output in the text you are writing.

If you are using MM's text mode to write the message, use control-p "to run a program and insert output". In this example, you insert a list of your files into the message, by using the ls command.

 Message (End with CTRL/D or ESC
  Use CTRL/B to insert a file, CTRL/E to enter editor, CTRL/F to run text
  through a filter, CTRL/K to redisplay message, CTRL/L to clear screen and
  redisplay, CTRL/N to abort, CTRL/P to run a program and insert output.):

Here are my files:

Command: ls


The output of the ls command is not shown on your screen, but the response [Done] tells you that the command was run successfully. If there was a problem, you would see sh: and then the usual error message from the UNIX shell; if you mistyped la for example it would respond with sh: la: not found.

At the S> prompt, use the display command to see the entire message, including the output from the command.

If you are using Emacs to write the message, you can use the standard Emacs command to insert output of a shell command, which is meta-1 meta-! followed by the command. The following shows the command line window at the bottom of the screen; actually M-1 M-! will appear briefly before you see the prompt Shell command.

-----Emacs: *MM Outgoing*          (Text Fill)----All--------------------------
Shell command: ls

-----Emacs: *MM Outgoing*          (Text Fill)----All--------------------------
Mark Set

At the end of the sequence above, the cursor (point) is placed at the beginning of the command output, and mark is at the end, so you can delete with just control-w if you change your mind. You can see the command output, and you can edit it just like the rest of the message.


The reverse of the preceding would be to take a message you received and send it as input to a command. The command would presumably process the text in some way. Use the list command with the special syntax |"command" (pipe, quote, command, quote). At the MM> prompt, add the message-sequence at the end; at the R> prompt, list acts on the message just read.

In the first example, message 16 is piped to a print command. The second example, perhaps contrived, the command used, grep, writes to standard output, so the result is displayed on screen (it shows lines containing the word topology, perhaps useful if the message contains a table of one-line items as this one seems to).

MM>list |"lpr -h -Piab1" 16
MM>list |"grep topology" 16
150309 Jan  9  1990 bitnet2.topology
168929 Jan  9  1990 bitnet3.topology
   688 Jun 12 13:52 bitnet.topology


Some commands can work as filters: they take standard input as input and write standard output as output. In MM's text mode, you can type control-f and a command, and the message text you have written will be piped into the command and replaced by the output of the command. An example is to run the text through the fmt program to fix the format; you want to end up only with the reformatted text, not add it to what you started with.

You can also filter with Emacs. Set mark and point around the material to be used as input, and type meta-1 meta-| and the filter command. This is superior to MM text mode because you can filter just part of the text.


When you start an MM process, by typing mm at the UNIX shell prompt, you can include an MM command as an argument. For example, type mm headers since mon at the shell prompt, and MM will start, get the main mail file, run the headers command, and then kill the process, putting you back at the shell prompt. This makes it possible to run certain MM commands inside a shell script, and MM's output can go to standard output (the screen) or be piped into another command in the shellscript. MM is meant to be interactive, so it is not always easy to script it.

The main limitation is that only one MM command can be passed as an argument; although the argument could be to tell MM to take an input file of MM commands, that is probably not the best way to do what you want. If you are trying to script sending mail, use restore-draft to read in text and follow with send mode commands like to and subject to fill in the headers; however, /usr/ucb/mail is better suited to the purpose.

The command line argument works only when starting a new process, so you should put the full path (probably /usr/local/bin/mm) in the shell script, since the simple command mm may be aliased to foreground an existing MM process when possible (full path is generally recommended in shell scripts anyway). The script won't be able to change the mail file if it is locked by an existing MM process.

[ Columbia MM Manual ]