Bash

Bash 中的粗體文本

  • December 31, 2019

我在這裡有一個範例腳本我想在文本中加粗粗體字並通過電子郵件發送。嘗試了幾種方法,但似乎不起作用。

BODY="Hello. I want to BOLD this"
{
echo "From: from@gmail.com"
echo "To: to@gmail.com"
echo "Subject: Texting"
echo "X-Mailer: htmlmail" $VERSION
echo "Mime-Version: 1.0"
echo "Content-Type: text/html; charset=US-ASCII"
print "<html><FONT COLOR=BLACK FACE="Geneva,Arial"SIZE=8><body>${BODY} </body>"

print "<html><FONT COLOR=BLACK FACE="Geneva,Arial"SIZE=10> ${BODY} </html>"
} | /usr/sbin/sendmail -t
  1. 您需要在電子郵件標題和正文之間有一個空行。
  2. 您試圖將雙引號錯誤地放在雙引號字元串中。

試試這個:

/usr/sbin/sendmail -t <<END_EMAIL
From: from@example.com
To: to@example.com
Subject: Texting
X-Mailer: htmlmail $version
Mime-Version: 1.0
Content-Type: text/html; charset=US-ASCII

<html><body><p><b>${BODY}</b></p></body></html>
END_EMAIL

這些變數可能有用

reset_colour=$(   tput sgr0)
bold=$(           tput bold)
black=$(          tput setaf 0)
red=$(            tput setaf 1)
green=$(          tput setaf 2)
yellow=$(         tput setaf 3)
blue=$(           tput setaf 4)
magenta=$(        tput setaf 5)
cyan=$(           tput setaf 6)
white=$(          tput setaf 7)
default_colour=$( tput setaf 9)

引用自:https://unix.stackexchange.com/questions/559719