[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

bash script - quotes in variables



Hi everybody,

I'm about to bang my head on the nearest wall, would you please point
me to my mistake.

Problem: I need to send scripted email with additional headers (like:
mail -a "Mime-version: 1.0" recipient@somewhere.org)

Okay, it works beautifully from an interactive prompt:
  mail -a "Mime-version: 1.0" -a approved:listpass -s "Test subject"
mylist@mysite.com

now I want to do that from inside a shell script:

============================

w3:~/bar# cat send.sh
#!/bin/sh
NEWSPAGE=/www/news/index.shtml
FILTER=/usr/local/lib/headlines/mailfilter.sed

MAIL_OPTS="-a 'Mime-version: 1.0' -a Approved:mypassword"
SUBJECT=`date +%D`


#lets preview the email command:
echo mail deemon@gmail.com $MAIL_OPTS -s "$SUBJECT"

#filter the news page and send it to the list
cat $NEWSPAGE | sed -f $FILTER| mail deemon@gmail.com $MAIL_OPTS -s "$SUBJECT"

w3:~/bar#  sh send.sh
mail deemon@gmail.com -a 'Mime-version: 1.0' -a Approved:mypassword -s 03/18/05
w3:~/bar#
============================

Now, here's what I see in my inbox:

----------
To: 1.0'@mydomain.com, deemon@gmail.com
Subject: 03/18/05
'Mime-version:
Approved:mypassword
----------

See? The single quotes seem to have lost their meaning, so
"Mime-version:" is in the headers, but "1.0" became a recipient. When
the above string is typed directly, everything works as a charm.

What am I doung wrong?

regards,
Dmitry



Reply to: