Next: , Previous: , Up: MFL   [Contents][Index]

4.9 Here Documents

Here-document is a special form of a string literal is, allowing to specify multiline strings without having to use backslash escapes. The format of here-documents is:

<<[flags]wordword

The <<word construct instructs the parser to read all the following lines up to the line containing only word, with possible trailing blanks. The lines thus read are concatenated together into a single string. For example:

set str <<EOT
A multiline
string
EOT

The body of a here-document is interpreted the same way as double-quoted strings (see Double-quoted strings). For example, if Sendmail macro f has the value jsmith@some.com and the variable count is set to 10, then the following string:

set s <<EOT
<$f> has tried to send %count mails.
Please see docs for more info.
EOT

will be expanded to:

<jsmith@some.com> has tried to send 10 mails.
Please see docs for more info.

If the word is quoted, either by enclosing it in single quote characters or by prepending it with a backslash, all interpretations and expansions within the document body are suppressed. For example:

set s <<'EOT'
The following line is read verbatim:
<$f> has tried to send %count mails.
Please see docs for more info.
EOT

Optional flags in the here-document construct control the way leading white space is handled. If flags is - (a dash), then all leading tab characters are stripped from input lines and the line containing word. Furthermore, if - is followed by a single space, all leading whitespace is stripped from them. This allows here-documents within configuration scripts to be indented in a natural fashion. Examples:

<<- TEXT
    <$f> has tried to send %count mails.
    Please see docs for more info.
TEXT

Here-documents are particularly useful with reject actions (see reject and tempfail syntax).


Next: , Previous: , Up: MFL   [Contents][Index]