Rewrite Once Prefix: $:
Ordinarily, the RHS rewrites the workspace as long as the workspace continues to match the LHS. This looping behavior can be useful. Consider the need to strip extra trailing dots off an address in the workspace:
R $* .. $1.
Here, the $*
matches any address that has two or more trailing
dots. The $1
. in
the RHS then strips one of those two trailing dots
when rewriting the workspace. For example:
xxx . . . . . becomes → xxx . . . . xxx . . . . becomes → xxx . . . xxx . . becomes → xxx . . xxx . . becomes → xxx . xxx . ← match fails
Although this looping behavior of rules can be handy, for most rules it can be dangerous. Consider the following example:
R $* <$1>
The intention of this rule is to cause whatever is in
the workspace to become surrounded with angle
brackets. But after the workspace is rewritten, the
LHS again checks for a match; and because the
$*
matches
anything, the match succeeds, the RHS rewrites the
workspace again, and again the LHS checks for a
match:
xxx becomes → < xxx > < xxx > becomes → < < xxx > > < < xxx > > becomes → < < < xxx > > > ↓ and so on, until ... ↓ sendmail prints: rewrite: expansion too long
In this case,sendmail catches the problem because the workspace has become too large. It prints the preceding error message and skips that and all further rules in the rule set. If you are running sendmail in test mode, this fatal error would also be printed:
= = Ruleset 0 (0) status 65
Unfortunately, not all such endless looping produces a visible ...
Get sendmail, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.