Sending multiple files as attachments by e-mail using mailx

advertisements

I have a requiremnet to send multiple files as e-mail attachmnet in shell script. I have used below command.

(printf "%s\n" "BODY"; uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt ) | mailx -m -s "TEST" [email protected]

However the number of files i want to send as an attachmnet are dynamic. So I want to assign the uuencode ... comand to a variable and then use it. I have tried below way,

$ ATTACH_CMD=$(echo `cat $OUTPUT_FILE`)
$ echo $ATTACH_CMD
uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt

$ (printf "%s\n" "BODY"; $ATTACH_CMD ) | mailx -m -s "TEST" [email protected]

And i am getting below error.

sh: uuencode out.txt out.txt ; uuencode asgda.txt asgda.txt:  not found.

Can any one please help me with this? Thanks in advance.


Have you tried using the below code? Not sure why it works, but maybe the below code could be used as a workaround

(printf "%s\n" "BODY"; `echo $ATTACH_CMD` ) | mailx -m -s "TEST" [email protected]`?

For $ATTACH_CMD I have used echo command.