procmail
[Top] [All Lists]

Re: $ interpretation and var ?? ? program

1997-01-19 21:46:43
dattier(_at_)wwa(_dot_)com (David W. Tamkin) writes:
Philip Guenther took on some of Jim Dennis's questions (most of which were
answerable with "Yes, Jim, you have it right").  I'd like to comment briefly
on one of Jim's questions and then get to a couple things Philip went into:

| >            * H ?? !^TO_whoever

Is that syntax valid?  I've never tried it, always using,

               * ! H ?? ^TO_whoever

I suppose it ought to work, but I've never noticed anyone using it before.

Procmail processes any mix of the leading 'specials', including '!',
'$', 'var ??', and 'w^x', in the order they appear, so that

FOO = BAR
BAR = 5^100
BAZ = '$QUUX ? cat >/tmp/foo; test -s /tmp/foo
QUUX = '$FOO ??'

:0
* $ $ \$$FOO $ $BAZ
/dev/null

Would result in procmail parsing the condition in the following stages:

        $ $ \$$FOO $ $BAZ
                        process leading $
        $ $BAR $ $QUUX ? cat >/tmp/foo; test -s /tmp/foo
                        process leading $
        5^100 $ $FOO ?? ? cat >/tmp/foo; test -s /tmp/foo
                        Set weight to 5 and exponent to 100
        $ $FOO ?? ? cat >/tmp/foo; test -s /tmp/foo
                        process leading $
        BAR ?? ? cat >/tmp/foo; test -s /tmp/foo
                        set egrep/pipe source to the variable BAR
        ? cat >/tmp/foo; test -s /tmp/foo
                        Ah, the actual test!

I would *not* suggest actually writing anything like the above unless
you're desperate for job security, or you have an _impossibly_ good
reason.


You don't need to backwhack the trailing dollar sign for that.  [nothing]
is not a valid variable name, so a trailing $ will survive unchanged under
interpretation by a leading $.  $something will be replaced with the value
of $something only if something is a valid name for a variable.

...and David one again magnaminously corrects and cleans up my
recipes.  That's the tragedy of having done too much of something: you
get stuck in your habits and have to _really_ watch yourself to prevent
the passing on of superstition.  I heartily recommend that new and
immeadiate procmail users harken to David's suggestion to use [$] for a
literal dollarsign, and ($) for a newline if confusion exists.  Old
fart experts should consider making their personal ruts shallower as
well.


| It appears from the source that the specified program will have
| whatever would have been grepped at it's standard in.  You could
| even say:
|
|      :0
|      * HOME ?? /some/program/that/wants/$HOME/on/its/stdin
|      ...etc

Wouldn't that need to be

      * HOME ?? ? /some/program/that/wants/$HOME/on/its/stdin
                ^^^

Yes.

Otherwise, you'd be checking whether the value of the variable $HOME contains
the string "/some/program/that/wants/
HOME/on/its/stdin".  If your home directory name includes that string, embed-
ded newline and all, shoot your sysadmin, please.

As a sysadmin, I'm _almost_ tempted to change my own home directory to
something like, or worse (embed *all* the shell metacharacters) just to
see how many programs and scripts break.


Anyhow, my understanding from somewhere in the man pages is that the H and
B *flags* do not affect programs called in exitcode conditions; they have the
entire incoming text at stdin (unless you use "H ??" or "B ??" on the condi-
tion line), just like programs called in VARIABLE=`program -opts args` as-
signments.

Well, I can find where it says that backquote expansions get the entire
message on stdin, but it never says what "? program" conditions have on
stdin, much less that they get anything at all, as far as I can tell.
This is a documentation bug if nothing else.  David, do you want to
send a doc correction to Stephen, or should I?

Here's a demo:

lunen% cat > foo
VERBOSE=on
:0B
* ? cat >bar
/dev/null
lunen% procmail -m foo
To: dsfhskjf
 
ksjhfskjfhsdkjfsd
^D
procmail: [21354] Sun Jan 19 21:47:24 1997
procmail: Executing " cat >bar"
procmail: [21354] Sun Jan 19 21:47:25 1997
procmail: Match on " cat >bar"
procmail: Assigning "LASTFOLDER=/dev/null"
procmail: Opening "/dev/null"
  Folder: /dev/null                                                          32
lunen% cat bar
ksjhfskjfhsdkjfsd
 
lunen%


Philip Guenther