procmail
[Top] [All Lists]

Re: sed syntex in procmailrc question

2011-10-15 12:05:56
On Fri, Oct 14, 2011 at 5:45 PM, Harry Putnam <reader(_at_)newsguy(_dot_)com> 
wrote:
Bart Schaefer <barton(_dot_)schaefer(_at_)gmail(_dot_)com> writes:

To expand just a little on Harry's correct explanation:

In the literal example you included, the single quotes around
's/SUBJET/' are unnecessary.  You only need quotes to protect spaces,
dollar signs, and globbing characters like *?[].

Again no expert here but let me move off sed for a moment since I'm
more familiar with awk.  Aren't there cases with awk where spaces are
not the issue but allowing a shell Variable to expand are what
matters?

Yes.  That's why I also mentioned "dollar signs, and globbing characters."

For example if you have a variable say, in the environment.  And you
want it to expand inside some awk code in .procmailrc.   Wouldn't you
need to do something like awk '/somestring/{print $0"'$MY_ENV_VAR'"}'

Yes, in that example (ignoring for now that $MY_ENV_VAR might expand
to something that breaks awk syntax) you do need to end the single
quotes before the environment variable reference and then resume
quoting again afterward.  In fact you may even mean:

awk '/somestring/{print $0"'"$MY_ENV_VAR"'"}'

Where there is one set of double quotes for awk (inside the shell
single quotes as in your original) and another set of double quotes
for the shell (outside but adjacent to the shell single quotes).
Unlike a lot of other programming languages, awk and (most) shells
automatically concatenate adjacent strings.  Double quotes in the
shell allow variable expansion but protect other special characters in
the expanded result.

(I inserted "(most)" because there are shells that use Perl or Tcl or
even Lisp syntax instead, but you'll probably never encounter one
unless you deliberately go looking.)

I realize there are other constructs that would serve the same purpose
and avoid quoting quagmires like:

 awk -v var=$MY_ENV_VAR '{print var}'

Incidentally that would also fail (or at least not do what you expect)
in many shells in the event that $MY_ENV_VAR contains special
characters.  You really need

awk -v var="$MY_ENV_VAR" '{print var}'

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

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