Re: sed syntex in procmailrc question

Bart Schaefer <[email protected]>
Newsgroups gmane.mail.procmail
Message-ID <CABkvzcsp2WdGZvkBKN1yF6uPqk0RghnPooW-OKQJuP0d4xp5=A@mail.gmail.com>
On Fri, Oct 14, 2011 at 5:46 AM, Harry Putnam <[email protected]> wrote:
> Zhiliang <[email protected]> writes:
>
>> I have a recipe wish 'sed' in one of my Smartlist rc, like:
>>
>>    sed 's/SUBJET/'"$SUBJ"/g
>>
>> which works fine.  I forgot where did I copied it from but have been
>> puzzled by its syntex with respect to the use of the single quotes
>> "'".
>
> I'm certainly not any kind of expert on sed but I think what you may
> be seeing is really a shell expansion thing.

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 *?[].

However, my guess is that your real sed expression, which you have not
shown us, doesn't have the string SUBJET but instead has a complex
string that might contain some of those special characters that need
quoting.

In that case for clarity I might have written such an expression as

sed -e s/'The Real String Goes Here'/"$SUBJ"/g

rather than butting the two sets of quotes up against each other.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.