Sean challenged,
| Please provide an example of this. Something demonstrating procmail
| taking an expression and assigning the results:
|
| myscore=$myscore + $=
|
| Doesn't work.
If $myscore is an integer or a decimal,
:0
* $ $myscore^0
* $ $=^0
{ }
myscore = $=
or if you need to preserve the previous value of $= as well,
interimscore = $=
:0
* $ $myscore^0
* $ $interimscore^0
{ }
myscore = $=
| If you weigh the previous score into each successive expression, don't you
| rub the risk of zeroing out an individual test (say, you had a -20 running
| score, and this recipe evaluated to 20, then ADDED the previous score:
|
| .. other scoring operations
| * $ $myscore^0
| {
| action
| }
|
| Would the action then not be executed?
Of course not. That's why, in case the result is zero or negative, we use a
null action (empty braces) and save the score in a variable after it.
| It just seemed dynamically adding the score would lead to instances where
| the score WOULD NOT be updated as a result of an intermediate test
| resulting in a zero value, and subsequently not revising the value of the
| carryover score.
Only if we save the score inside the braces rather than after them.
| Please, feel free to rewrite the given script such that it works using
| scoring for the carryover math, keeping in mind the potential for a zero
| effect at some stage.
I just did.
Earlier, when Sean had written,
< | formail -I "X-MyScore: $(( 1 * $myscore ))"
I responded,
How, except for burning cycles, is that going to give different results
from
| formail -I "X-MyScore: $myscore"
He answered,
| ... $myscore ... isn't just a number, it's [a] longhand expression:
Oh, I hadn't understood that. Sorry. Thanks for re-explaining that. But
if I erred there, I totally blew it here:
* $ $((myscore>LIMIT))
where ">" will serve as the requisite visitor from $SHELLMETAS.
Yikes. $SHELLMETAS doesn't apply to regexp conditions, except perhaps
inside backquote substitution when the "$" modifier is present. Since
procmail's own variable substitution doesn't do arithmetic, nor does it
substitute values for variable names inside double parentheses if they don't
have dollar signs [ksh and pdksh do: you do not need dollar signs on
variables inside double parentheses; however, procmail was trying to handle
that on its own], that wouldn't work. I really goofed there, as Sean saw:
| to wit:
| procmail: No match on "((10+12>20))"
| or (if executed AS you wrote it -- without $ on the variables):
| procmail: No match on "((myscore>LIMIT))"
But something like this, where $SHELL is one that includes $(( ))
arithmetic,
* ! ? exit $((myscore>LIMIT)) # here ">" works as a shell metacharacter
seems to work (using ksh for the test) whether $LIMIT is a number or an
arithmetic expression. If $LIMIT includes operators of lower precedence
than comparison, though, you'll need to do this:
* ! ? exit $((myscore>(LIMIT)))
Also, it's just nastily counterintuitive that, because ksh arithmetic
generates 1 for truth and 0 for falsehood, you have to invert the outcome to
make procmail consider truth a match and falsehood a mismatch, just the
opposite of what happens when you use test. And in any case, it still needs
a shell.
So to the question: if $LIMIT is an arithmetic expression rather than a
simple integer or decimal value, how do we add it to $myscore within
procmail without using a shell nor expr nor bc? I guess we can't. Since bc
needs it as standard input we have to call a shell to pipe echo to bc; expr,
on the other hand, can take the expression as command line arguments but
needs all the numbers and operators separated with spaces or tabs. So a
shell like bash or ksh that supports arithmetic is probably the best general
answer. I see your point, Sean; sorry it went over my head before.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail