You are here

Sending e-mail with multiple lines in bash script

Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

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.