You are here

Sending e-mail with multiple lines in bash script

Recently I've had to write a bash script which sends an e-mail alert message when it's needed. The text of the e-mail should be written in multiple lines.

My first thought was to use \n character to separate lines, but unfortunately that doesn't work.

After a little research I finally found a pretty good solution for the problem - we can use functions in bash scripts as well:


function high_alert_mail {
  echo "Temperature is TOO HEIGHT:"
  echo " - alert limit: $ALERT_MAX"
  echo " - measured temperature: $TEMP1"
  echo " - time of measurement: $TIME_DISPLAY"


high_alert_mail | mail -s "Temp error - PI" account@host.loc

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.