1

I'm trying to send mail using Mailx and uuencode with attachments using the following in a shellscript

attachments=uuencode file1 file1;uuencode file2 file2;

(echo BODY ; $attachments )| mailx -s "Attachments" -m [email protected]

For the above script only mail without attachment is sent,However when i use the following

(echo BODY ; uuencode file1 file1;uuencode file2 file2;)| mailx -s "Attachments" -m [email protected]

Now mail is sent with the attachments.

I'm fairly new shellscripting kindly help.

1
  • 1
    So what's the problem? Commented Jul 17, 2014 at 4:05

1 Answer 1

1

You are using the wrong quotes for command substitution:

attachments=`uuencode file1 file1;uuencode file2 file2`

or better

attachments=$( uuencode file1 file1;uuencode file2 file2 )

See the Command Substitution section of the bash man page

And then use echo to output the variable content

(echo BODY ; echo $attachments )| mailx -s "Attachments" -m [email protected]
Sign up to request clarification or add additional context in comments.

3 Comments

This gives you the output, like you commented on my answer, but that won't send the attachment when you pipe it. You need to pipe the output of the command, so the first part (echo BODY; $attachments) needs whatever $attachments expands to to be a command, otherwise you'll hit some error like Begin: Command not found
@chrisb2244 Thanks I didn't notice the missing echo. I updated the answer.
mailx handles uuencoding of attachments on the fly. So why not echo "body" | mailx -s "Attachments" -a file1 -a file2 [email protected] That seems easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.