procmail
[Top] [All Lists]

Re: Comparing variables....

1999-04-14 18:45:10
"Randy James" <rjames(_at_)bu(_dot_)edu> writes:
I know I am just piling on the mail, but one more thing...

I sucked a file into a variable using:
VAR = `cat myfile`

Now I want to check to see if a variable (VAR2) exists within the file.
I've tried things like
* FILE ?? $VAR2
But I just don't know the syntax well enough to get it right.
I want a complete match.  VAR2 must be nested within FILE for the condition
to succeed.

Where did that variable FILE come from?  Did you mean VAR?  If so, you're
close.  You need two dollarsigns, one to tell procmail to perform variable
expansion of the pattern, and one for the variable itself.  If you want
to match the literal contents of VAR2 and not treat its contents as a
regular expression then you'll want to use $\VAR2:

        :0
        * VAR ?? $ $\VAR2
        |whatever...

You may also want to anchor the regular expression, in case you want
the contents of VAR2 to be an entire line in the file:

        :0
        * VAR ?? $ ^$\VAR2($)
        |whatever...


The other point to remember is that if you try to slurp a file larger
than $LINEBUF in size then procmail will truncate the data that it
stores into VAR.  Beware of simply setting LINEBUF to a huge value:
such an assignment causes procmail to immeadiately allocate twice that
much memory (procmail has two buffer internally of size $LINEBUF).

Philip Guenther

<Prev in Thread] Current Thread [Next in Thread>