Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

email from bash script

Tags:

bash

#!/bin/bash
MESSAGE="Line one. /n"

MESSAGE="$MESSAGE Line two. /n"
MESSAGE="$MESSAGE Line three."

echo $MESSAGE | mail -s "test" "[email protected]"

Is that how I should get each line, on its own line?

like image 270
Jim Avatar asked Feb 16 '10 19:02

Jim


2 Answers

Use a heredoc.

mail -s "test" "[email protected]" << END_MAIL
Line one.
Line two.
Line three.
END_MAIL
like image 72
Matthew Flaschen Avatar answered Sep 22 '22 09:09

Matthew Flaschen


Change:

echo $MESSAGE | mail -s "test" "[email protected]"

To:

echo -e $MESSAGE | mail -s "test" "[email protected]"
like image 23
Jim Avatar answered Sep 22 '22 09:09

Jim