procmail
[Top] [All Lists]

Re: =| and newlines

2001-08-28 23:02:53
Don Hammond <procmail1(_at_)tradersdata(_dot_)com> writes:
On 27 Aug, Robert Brown wrote:
| This is probably an FAQ, but I cannot find the answer.
| 
| Apparently, =| embeds any newlines that occur in the command into the
| variable.  For example,

Umm, no.  In fact, the exact opposite is true: when processing a variable
capture recipe, procmail strips *all* trailing newlines from the output
before setting the variable.

That's not to say that there can't be newline in the middle of the value.
There just won't be any right at the end.


| :0
| FOO=|echo 4 \* 5 | bc
| 
| lets FOO have a newline as the last character in it.


Let's just give that a try:

        $ cat rcfile

        VERBOSE = on

        :0
        FOO=|echo 4 \* 5 | bc

        BAR = "$FOO"

        :0
        /dev/null
        $ procmail ./rcfile  </dev/null
        procmail: [16642] Tue Aug 28 22:35:15 2001
        procmail: Assigning "FOO="
        procmail: [16642] Tue Aug 28 22:35:15 2001
        procmail: Executing "echo 4 \* 5 | bc"
        procmail: Assigning "BAR=20"
        procmail: Assigning "LASTFOLDER=/dev/null"
        procmail: Opening "/dev/null"
        procmail: Notified comsat: "guenther(_at_)0:/dev/null"
          Folder: /dev/null                                                0
        $

I see no trailing newline on BAR.  If you're wondering about the
        Assigning "FOO="
line, that's just procmail telling you that it's about to assign to FOO.
There's no value shown because procmail hasn't read it in yet.


| For example,
| 
| :0
| BAR=|sed -e 's/XXX/'$FOO'/'
| 
| later in the script will fail due to the embedded new-line.

First of all, you should be using double quotes for something like this:

        :0
        BAR=|sed -e "s/XXX/$FOO/"

If you still get errors around there after you've fixed the quoting,
then you should post to the list again and include the exact log entries
that show it failing.  Preferably with VERBOSE=on somewhere further up.


| (I cannot use `command` (backticks) because I need to check the return
| status of the command.)

The status of the last command executed by procmail can always be found
in $?.  Testing against it is more complicated...



Don Hammond <procmail1(_at_)tradersdata(_dot_)com> noted:
This is only a guess, but are you tring to modify and assign to BAR in
one fell swoop?  In other words, are you expecting the existing value
of BAR to be the input to sed, with the output being assigned back to
BAR?  If so, that's not what this is doing. In fact, AFAICT you can't do
BAR=| echo $BAR |sed ... either. Another variable is required as I did
above.

Actually, while that used to be true, it changed in version 3.14; to
quote the HISTORY file:

1999/11/22: v3.14
            Changes to procmail:
...
               - Variable capture actions now see the variable's current value
                 and restore it if the action fails.  Previously unset
                 variables will remain unset.

Of course, since we don't know what version of procmail he's using,
it's a good thing to warn about.


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

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