I'm having a issue with sendmail. I'm sending echo multiple text with sendmail (1 liner) but it isn't breaking up the line.

my code is like this:

$ echo "$text1\n$text2\n$text3\n$text4 | mail -s "subject" myemail

But somehow it just doesn't break the line, any tips?

  • Use echo -e "$text1\n$text2\n$text3\n$text4" | mail -s "subject" myemail – Scyld de Fraud Sep 16 '14 at 10:11
  • echo -e didnt work, in my mail as output it showed "-e" before my text. – tamani Sep 16 '14 at 10:26
  • You must have put -e inside quotes… I using it a lot. Works for 100%! – Scyld de Fraud Sep 16 '14 at 10:42

Try this:

 $ printf "$text1\n$text2\n$text3\n$text4" | mail -s "subject" myemail

NOTE: (assuming no % in $text)

You can also do it like this too:

$ (echo $text1 ;echo $text2 ;echo $text3 ;echo $text4 ) | \
    mail -s "subject" myemail

This last one creates a sub-shell with the parens wrapping the output of all the echo's. That output is then piped to the mail command.

| improve this answer | |
  • arche, you are a hero, it worked. you helped me so often. thanks man. – tamani Sep 16 '14 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.