011#ANSI颜色系列

#!/bin/bash
# ANSI color ---

initializeANSI()
{
  esc="\e"    # 同'\033'

  # 前景色:
  blackf="${esc}[30m";
  redf="${esc}[31m";
  greenf="${esc}[32m";
  yellowf="${esc}[33m";
  bluef="${esc}[34m";
  purplef="${esc}[35m";
  cyanf="${esc}[36m";
  whitef="${esc}[37m";

  # 背景色:
  blackb="${esc}[40m";
  redb="${esc}[41m";
  greenb="${esc}[42m";
  yellowb="${esc}[43m";
  blueb="${esc}[44m";
  purpleb="${esc}[45m";
  cyanb="${esc}[46m";                                                                                               
  whiteb="${esc}[47m";

  # 粗体、斜体、下划线以及样式切换:

  boldon="${esc}[1m";
  boldoff="${esc}[22m";
  italicson="${esc}[3m";
  italicsoff="${esc}[23m";
  ulon="${esc}[4m";
  uloff="${esc}[24m";
  invon="${esc}[7m"; # 反色,前景色与背景色互换
  invoff="${esc}[27m";
  reset="${esc}[0m"
}

initializeANSI
echo -e "
${yellowf}This is a phrase in yellow${redb} and red background.${reset}
${boldon}This is bold ${ulon}this is underline${reset}
${italicson}This is italics${italicsoff} and ${reset}reset to nornal
${yellowf}${redb}Warning 1${yellowb}${redf}Warning 2${reset}
${invon}${yellowf}${redb}Warning 1${invoff}${yellowb}${redf}Warning 2${reset}
"
posted @ 2020-06-01 23:13  bigtree2pingping  阅读(235)  评论(0编辑  收藏  举报