-1

We have created a UNIX program which is used to send mails. In that program we are fetching the mail subject and body based on user inputs (through Oracle Concurrent Program)

For example:

The complete user inputs of concurrent program are storing in $1 variable which is as below:

XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" \
FCP_USERID=5667 \
FCP_USERNAME="SRI" \
FCP_PRINTER="noprint" \
FCP_SAVE_OUT=Y \
FCP_NUM_COPIES=1 \
"9614556_SUP12_XX_Workflow_Stuck_AP_Invoices.csv" \
"/tmp_mnt2/attachments" \
"Sri.B@xx.com" \
"This is the subject for the mail" \
"PFA for the list of Invoices that are stuck in workflow."

Here, subject for mail is This is the subject for the mail which we are storing in variable SUB and body for mail is PFA for the list of Invoices that are stuck in workflow. which we are storing in another variable FCP_BODY.

Now, I wrote as below to send mail

echo "Hello,
${FCP_BODY}
Thanks,
Bommi
"| mailx -s $SUB

But, in the mail I received, the body is coming properly, but subject is coming just This.

Can anyone please help me on how to fetch the complete subject to send mail?

dr_
  • 29,602
Bommi
  • 25

1 Answers1

2

You need to quote the variable $SUB:

... mailx -s "$SUB"

Explanation: A variable containing spaces is going to be subject to word splitting. That is, if you have the command

mailx -s $SUB

and the variable $SUB contains the string "This is the subject for the mail"

the previous command gets expanded as

mailx -s This is the subject for the mail

i.e. the -s flag (Subject) gets only the argument This, and the rest of the words are passed as other arguments, and (in most cases) handled like garbage.

Instead,

mailx -s "$SUB"

gets expanded as

mailx -s "This is the subject for the mail"

which is what you wanted.


Related questions and answers:

dr_
  • 29,602