首頁 > Linux, 未分類 > Shell script輸出有顏色的文字

Shell script輸出有顏色的文字

2011年7月22日 Austin 發表評論 閱讀評論
# Color defination
txtRed=$(tput setaf 1)
txtGreen=$(tput setaf 2)
txtYellow=$(tput setaf 3)
txtBlue=$(tput setaf 4)
txtPurple=$(tput setaf 5)
txtCyan=$(tput setaf 6)
txtWhite=$(tput setaf 7)
txtReset=$(tput sgr0)

# Style defination
txtBold=$(tput bold)
txtUL=$(tput smul)

# Example
echo "${txtRed}Red text"
echo "still Red text"

echo "$txtReset"
echo "Normal text"

Reference: How to echo colored text in linux shell script

Categories: Linux, 未分類 Tags: , , , ,
  1. 目前尚無任何的評論。
  1. 目前尚無任何 trackbacks 和 pingbacks。