procmail
[Top] [All Lists]

Re: Dallman - virussnag file - question

2003-09-20 04:28:20
On Fri, Sep 19, 2003 at 09:06:44PM -0600, LuKreme wrote:

On Sep 19, 2003, at 6:19 PM, Ken Douglass @pacbell.net wrote:

Hi Dallman,
In your "virussnag" file I see this expression:
MYVIRUS  = "${MYVIRUS:-VIRUS}"

I believe that says "set MYVIRUS to $MYVIRUS if it's defined,
otherwise set it to the literal text 'VIRUS'," but I don't know WHY.
I found a small mention of the ${VAR:-text} format in man procmailrc

"Why" is because procmail adheres to standard shell nomenclature here.
The syntax comes from the Bourne-shell family, and the man pages
for those shells explain it.

From "man sh":

     In addition, a parameter expansion can be modified by using
     one of the following formats.

     ${parameter:-word}    Use Default Values.  If parameter is
                           unset or null, the expansion of word
                           is substituted; otherwise, the value
                           of parameter is substituted.

     ${parameter:=word}    Assign Default Values.  If parameter
                           is unset or null, the expansion of
                           word is assigned to parameter.  In all
                           cases, the final value of parameter is
                           substituted.  Only variables, not
                           positional parameters or special
                           parameters, can be assigned in this
                           way.

     ${parameter:?[word]}  Indicate Error if Null or Unset.  If
                           parameter is unset or null, the
                           expansion of word (or a message
                           indicating it is unset if word is
                           omitted) is written to standard error
                           and the shell exits with a nonzero
                           exit status.  Otherwise, the value of
                           parameter is substituted.  An
                           interactive shell need not exit.

     ${parameter:+word}    Use Alternative Value.  If parameter
                           is unset or null, null is substituted;
                           otherwise, the expansion of word is
                           substituted.

     In the parameter expansions shown previously, use of the
     colon in the format results in a test for a parameter that
     is unset or null; omission of the colon results in a test
     for a parameter that is only unset.


searching for regex info was not that helpful either, even after
checking man regex and man regcomp.  Man expr has this to say:

Well, it's parameter expansion, as opposed to regex stuff.  It's
basic shell syntax, that the procmail creator consciously decided
to allow the program to recognize as well.

One does need to keep in mind, though, that in procmail there is
no real difference between unset and set-to-null; at least in
how we read or expand the parameters inside procmail.  So

        FOO =

sets FOO to nothing, while

        FOO

unsets FOO.  But the same test would apply to see if there's
something in FOO:

        :0
        * FOO ?? .
        | do_domething

("If FOO is set and not empty, do something.")

-- 
dman

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail