<dman(_at_)walkerect(_dot_)com>
Bcc:
Subject: Re: quoting when calling external commands from a recipe
Reply-To:
In-Reply-To:
<200004260325(_dot_)PAA05268(_at_)lupus(_dot_)elec(_dot_)canterbury(_dot_)ac(_dot_)nz>;
from kuhlmav(_at_)elec(_dot_)canterbury(_dot_)ac(_dot_)nz on Wed, Apr 26, 2000
at 03:25:06PM +1200
Volker Kuhlmann <kuhlmav(_at_)elec(_dot_)canterbury(_dot_)ac(_dot_)nz> [000425
23:26]:
[lots of good stuff skipped]
What about handing $MATCH over to sed, e.g. when replacing SOMETHING
with $MATCH, as in
sed -e 's/\$SUBJECT/'"$MATCH"'/g' <$PROCDIR/vacationmsg
Things will fail badly!
1) The double-quotes around $MATCH are necessary to make the whole
's/.../.../g' only one argument to sed (shell escape).
But the double quotes can replace the single quotes as well in this
case. "s/\\$SUBJECT/$MATCH/g" will do.
Here is a test harness and some auxiliary files which demonstrate how to
surmount this problem.
=====8<-----begin files------------------------------------------
=====8<-----harness.rc-------------------------------------------
SHELL=/bin/sh
MAILDIR=.
DEFAULT=|
nl="
"
LOG="# Procmail version $PROCMAIL_VERSION${nl}# On $HOST$nl"
s=${s:-\\//&}
LOG="The test subject is $s$nl"
msg=`echo "With regard to your recent note${nl}entitled: $s"; cat ./canned`
:0
* s ?? [&\/]
{ s=`echo $s | sed -e 's,\\\\,\\\\\\\\,g' -e 's/&/\\\\&/g' -e 's,/,\\\\/,g'` }
:0
{ msg2=`sed "s/\\$SUBJECT/$s/" < ./canned2` }
LOG="${nl}# Generated with echo and cat:$nl$msg$nl"
LOG="${nl}# Generated with messy sed substitutions:$nl$msg2$nl"
HOST=byebye
=====8<-----canned-----------------------------------------------
I will get back to you three weeks from yesterday.
Maybe.
=====8<-----canned2----------------------------------------------
This is a canned response about your message with the
subject: $SUBJECT
I will get back to you three weeks from yesterday.
Maybe.
=====8<-----end files--------------------------------------------
procmail ./harness.rc s='///&\\\\\\//\\\\<p/\\"' < /dev/null
To operate, cut all files into appropriately named files in the same
directory and invoke as shown above. If you do not define s in the
invocation, a default value will be used. Add VERBOSE=yes to the
invocation for a better view.
NOTE: If you use doublequotes in the invocation (s="test subject") be
sure to double all \s.
If you simply want to place one copy of the subject into a canned
message, echo (or print) and cat are much simpler. If you get the
\-quoting wrong on sed, you could leave yourself open to having files
overwritten (consider what the w flag does on sed substitutes).
Of course, I could be oversimplifying. There may be more problems than
I've handled waiting to bite me.
--
Rik