Next: , Previous: Reading Mail, Up: mail


2.4.5 Scripting

Comments

The ‘#’ character introduces an end-of-line comment. All characters until and including the end of line are ignored.

Displaying Arbitrary Text

The ‘echo’ (‘ec’) command prints its arguments to stdout.

Sourcing External Command Files

The command ‘source filename’ reads commands from the named file. Its minimal abbreviation is ‘so’.

Setting and Unsetting the Variables

The mail variables may be set using ‘set’ (‘se’) command. The command takes a list of assignments. The syntax of an assignment is

name=string
Assign a string value to the variable. If string contains whitespace characters it must be enclosed in a pair of double-quote characters (‘"’)
name=number
Assign a numeric value to the variable.
name
Assign boolean True value.
noname
Assign boolean False value.

Example:

     & set askcc nocrt indentprefix="> "

This statement sets askcc to True, crt to False, and indentprefix to “> ”.

To unset mail variables use ‘unset’(‘uns’) command. The command takes a list of variable names to unset.

Example: To undo the effect of the previous example, do:

     & unset askcc crt indentprefix
Setting and Unsetting Shell Environment Variables

Shell environment may be modified using ‘setenv’ (‘sete’) command. The command takes a list of assignments. The syntax of an assignment is:

name=value
If variable name does not already exist in the environment, then it is added to the environment with the value value. If name does exist, then its value in the environment is changed to value.
name
Delete the variable name from the environment (“unset” it).
Conditional Statements

The conditional statement allows to execute a set of mail commands depending on the mode the mail program is in. The conditional statement is:

     if cond
     ...
     else
     ...
     endif

where ‘...’ represents the set of commands to be executed in each branch of the statement. cond can be one of the following:

s
True if mail is operating in mail sending mode.
r
True if mail is operating in mail reading mode.
t
True if stdout is a terminal device (as opposed to a regular file).

The conditional statements can be nested to arbitrary depth. The minimal abbreviations for ‘if’, ‘else’ and ‘endif’ commands are ‘i’, ‘el’ and ‘en’.

Example:

     if t
     set crt prompt="& "
     else
     unset prompt
     endif
     if s
     alt gray@farlep.net gray@mirddin.farlep.net
     set