procmail
[Top] [All Lists]

Re: Using variables in recipes

2007-06-08 11:42:28
On Fri, Jun 08, 2007 at 06:01:14PM +0100, Stephen Allen wrote:

Thanks Alan LuKreme and Dallman,

If it helps the explanation a little, let's say I wanted to set
2 variables because of some condition that was met in a recipe.
From what people have said, the below example is wrong, but it's
the kind of thing I'm after...

:0
* Some condition
{
    MYVAR=this
    YOURVAR=that

    :0
    * Another condition (now I've set variables as a result of top 
condition)
    Another action
}

Better explanation of my question?  I won't know what to set
MYVAR and YOURVAR to until the first condition has been met.

That is how it's supposed to be done.  That's also what Kremey showed,
pretty much.  You go into a nested block and then have other stuff.
the "other stuff" is always the same "stuff" that can ever always
go in an rcfile: (1) the setting of environment variables; or (2)
recipes.  This, coincidentally (or not), is what "man procmailrc" also says
near the top:

   DESCRIPTION
       For a quick start, see NOTES at the end of the procmail(1)
       man page.

       The rcfile can contain a mixture of environment variable
       assignments (some of which have special meanings to
       procmail), and recipes. . . .

This is different from what you posted yesterday, I'll note.  There
you had a nested block that started with two naked action statements.
An action by itself is never allowed in the rcfile; it always is
the final part of a recipe.  (Recipes may have zero conditions.)

You can also use backticks when setting variables.  I believe you
know this already.  E.g.,

   FOO = `ls -tAF | grep -v / | head -1`  # newest file in current dir

But that is still not an "action," in procmail parlance, but rather
a variable assignment.

Variable assignments, you can have anywhere, except not in the midst
of recipes.[1]

[1] The MATCH var is volatile and can be reinstantiated in the middle
of a recipe, however.

Dallman
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail