GNU Mailutils Manual (split by node):   Section:   Chapter:FastBack: Programs   Up: configuration   FastForward: Libraries   Contents: Table of ContentsIndex: Function Index

3.2.2 Configuration Variables

Certain configuration statements allow for the use of variable references in their values. A variable reference has the form ‘$variable’ or ‘${variable}’, where variable is the variable name. It is expanded to the actual value of variable when Mailutils consults the configuration statement in question.

The two forms are entirely equivalent. The form with curly braces is normally used if the variable name is immediately followed by an alphanumeric symbol, which will otherwise be considered part of it. This form also allows for specifying the action to take if the variable is undefined or expands to an empty value.

During variable expansion, the forms below cause Mailutils to test for a variable that is unset or null. Omitting the colon results in a test only for a variable that is unset.

${variable:-word}

Use Default Values. If variable is unset or null, the expansion of word is substituted. Otherwise, the value of variable is substituted.

${variable:=word}

Assign Default Values. If variable is unset or null, the expansion of word is assigned to variable. The value of variable is then substituted.

${variable:?word}

Display Error if Null or Unset. If variable is null or unset, the expansion of word (or a message to that effect if word is not present) is output to the current logging channel. Otherwise, the value of variable is substituted.

${variable:+word}

Use Alternate Value. If variable is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

${variable:|word1|word2}

Display Alternative Values. Unless variable is null or unset, the expansion of word1 is substituted, otherwise the expansion of word2 is substituted.

The following constructs provide for modifying the value of the variable. In each of them, globbing pattern matching notation is used to evaluate patterns.

${variable#word}

Remove Shortest Prefix Pattern. The word is expanded to produce a pattern. If that pattern matches the beginning of the expanded value of variable, then this construct expands to the expanded value of variable with the shortest matching pattern removed.

${variable##word}

Remove Longest Prefix Pattern. The word is expanded to produce a pattern. If that pattern matches the beginning of the expanded value of variable, then the result of the expansion is the expanded value of variable with the longest matching pattern removed.

${variable%word}

Remove Shortest Suffix Pattern. The word is expanded to produce a pattern. If that pattern matches a trailing portion of the expanded value of variable, then the result of the expansion is the expanded value of variable with the shortest matching pattern removed.

${variable%%word}

Remove Longest Suffix Pattern. The word is expanded to produce a pattern. If that pattern matches a trailing portion of the expanded value of variable, then the result of the expansion is the expanded value of variable with the longest matching pattern removed.

${variable/pattern/subst}

Pattern Substitution. Both pattern and subst are expanded. variable is expanded and the longest match of pattern against its value is replaced with the expansion of subst. By default only the first match is replaced. If pattern begins with ‘/’, all matches of pattern are replaced with subst. If it begins with ‘#’, the match is replaced only if it occurs at the beginning of the expanded value of variable. Conversely, if it begins with ‘%’, the match is replaced only if it occurs at the end of the expanded value of variable. To match the special characters (‘/’, ‘#’, or ‘%’) literally, precede them with a backslash.

If the pattern does not match the expanded variable, the five constructs above result in the expanded value of the variable unchanged.

In any expansion form, the word part is treated exactly as in Bourne shell: it can contain variable expansions, command substitutions, single and double-quoted parts. The latter two are interpreted as follows: the quotes are removed, the text between double quotes is subject to variable expansion and command substitution (see below), whereas the test between single quotes is not. Within double quoted part, a backslash can be used to escape the indirection character (‘$’), double and single quote characters and backslash itself.

When a value is subject to variable expansion, it is also subject to command expansion. Commands are invoked in string values using the following format:

$(cmd arg)

where cmd is the command name, and args is a list of arguments separated by whitespace. Arguments can in turn contain variable and command references.

The following commands are defined:

Command: localpart string

Treats string as an email address and returns the part preceding the ‘@’ sign. If there is no ‘@’ sign, returns string.

Command: domainpart string

Treats string as an email address and returns the part following the ‘@’ sign. If there is no ‘@’ sign, returns empty string.

Command: localuser string

If string is an email address with user and detail subparts in its localpart, this function returns the user name. Otherwise, it is equivalent to localpart:

$(localuser "smith+lists@example.com") ⇒ "smith"
$(localuser "smith@example.com") ⇒ "smith"
Command: detail string

If string is an email address with user and detail subparts in its localpart, this function returns the detail part. If no detail part is present, it returns an empty string:

$(localuser "smith+lists@example.com") ⇒ "lists"
$(localuser "smith@example.com") ⇒ ""
Command: shell cmd args

Runs the shell command cmd with the given arguments. Returns the standard output from the command. The command is invoked using /bin/sh -c and can contain any valid shell constructs.

The subsections below define variable names that are valid for use in each configuration statement.

GNU Mailutils Manual (split by node):   Section:   Chapter:FastBack: Programs   Up: configuration   FastForward: Libraries   Contents: Table of ContentsIndex: Function Index