Occasionally, it is necessary to test a macro to see whether
a value has been assigned to it. To perform such a test, a special
prefix and two operators are used. The general form is
$?x text1 $| text2 $.
is defined if
is not defined
This expression yields one of two possible values:
if the macro named
has a value,
The entire above expression, starting with the
ending with the
, yields a single value, which
may contain multiple tokens.
The following, for example, includes
the configuration-file version
in the SMTP greeting message but does so only if
that version (in
) is defined:
O SmtpGreetingMessage=$j Sendmail ($v/
) ready at $b
Here the parenthetical version information is expressed one
has a value (like
but is expressed differently if
lacks a value:
of this conditional expression is optional.
If it is omitted, the result is the same as if the
Both of the preceding yield the same result. If
has a value, then
becomes the value of the entire expression. If
lacks a value, then the entire expression lacks a value (produces
Note that it is
advisable to use the
conditional expression in rules. It may not have the
intended effect, because macro conditionals
are expanded when the configuration file is read.
allows conditionals to nest.
To illustrate, consider the following expression:
$?x $?y both $| xonly $. $| $?y yonly $| none $. $.
This is just like the example in the previous section:
$?x text1 $| text2 $.
are both conditionals:
text1 = $?y both $| xonly $.
text2 = $?y yonly $| none $.
The grouping when conditionals nest is from the outside in. In the
following example, parentheses have been inserted to show the
groupings (they are not a part of either expression):
$?y both $| xonly $.
$?y yonly $| none $.
Interpretation is from left to right.
The logic of the second line above is therefore this:
have values, the result is
has a value
lacks one, the result is
lacks a value but
has one, the result is
And if both lack values, the result is
program does not enforce or check for balance
in nested conditionals. Each
should have a corresponding
to balance it. If they do not balance,
will not detect the problem. Instead, it may interpret the
expression in a way that you did not intend.
The depth to which conditionals may be nested
is limited only by our ability to easily comprehend the result.
More than two deep is not recommended,
and more than three deep is vigorously discouraged.