On Thu, 30 Sep 1999 13:34:27 -0500, David Stone
<dstone(_at_)chem(_dot_)utoronto(_dot_)ca> wrote:
David W. Tamkin suggested:
MATCH
:0c # ,,acknowledgement'' is Canadian spelling
* ! ^FROM_DAEMON
* $ ! ^X-Loop: $LOGNAME
* other conditions if any
* 1^0 ^Subject:\/.*
* 1^0
| formail -rkbt -I "Subject: Autoreply${MATCH+ (was $MATCH)}" \
-A "X-Loop: $LOGNAME" \
-I "Precedence: junk" \
-A "X-Comment: Auto-acknowledgement" | \
sed -e '1,/^$/ !b' -e "/^$/r $PMDIR/autoack.txt" | \
$SENDMAIL -oi -t
Ugh, that second-last line looks ugly! What does the /^$/ signify?
Is there some subtle distinction in sed between a script in ' '
and one in " " ?
The /^$/ matches the first totally empty line (matching the regex
start of line ^ immediately adjacent to end of line $) -- with the
action !b, we get "for all of the message apart from the part up to
the first empty line, just print, no substitutions, etc".
sed itself doesn't even get to see the quotes. The shell treats stuff
in double quotes differently from stuff in single quotes. All the
quotes are removed before sed even starts; those are handled by the
shell.
Single quotes are protective, so the first -e is passed in verbatim.
Double quotes are subject to variable substitution, which is what we
want, because we want $PMDIR substituted with the value of the
variable. After substitution, what gets passed to sed look something
like /^$/r /home/you/procmail/autoack.txt which says to insert the
contents of the named file at this point, then continue with the
script as usual.
The first -e argument could be in double quotes as well if you have a
shell which doesn't treat ! specially. My /bin/sh doesn't, but e.g.
bash (which is aliased to /bin/sh on many systems, e.g. most Linux
systems) uses it for job control, so you get '!b": event not found' if
you try double quotes. (I guess this should be regarded as an error;
bash ought to emulate stock [or actually POSIX] /bin/sh as closely as
possible when invoked as /bin/sh.)
To recap, here's the script in pseudo code
if not looking at the headers (up to and including the "neck", the
empty line between the headers and the body),
branch to "implicit label"
if looking at an empty line (i.e. the neck), include the named file
implicit label:
implicitly: when you get to the end of the explicit script, print
the current input line
Sorry for posting an incorrect script earlier; I'm afraid I was asleep
at the wheel for a bit there. And hope this helps,
/* era */
$ /bin/sh -c 'echo "/^$/ !b"'
/^$/ !b
$ /usr/local/bin/bash -c 'echo "/^$/ !b"'
/^$/ !b
Hey, that's not what it did when I invoked it interactively. But
earlier versions of Bash might not work right even when invoked from
within Procmail. And don't even think about Csh (shudder)
--
Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition