着色文字

时间:2012-10-24 17:56:20

标签: bash

如何用Bash显示彩色文字?

  • a:棕色背景上的白色文字
  • b:黄色背景上的黑色文字

echo -e "bbb aaa bbb"

echo -e "aaa bbb aaa"

我的结果不太好: - (

2 个答案:

答案 0 :(得分:3)

# text
black='\e[0;30m'
white='\e[0;37m'
yellow='\e[0;33m'

# background
white_bg='\e[47m'

echo -e "${black}black test"
echo -e "${white_bg}white bg and black test"
echo -e "${yellow}yellow test"

答案 1 :(得分:1)

您可以在~/.bashrc

中提供这些颜色
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White

之后您可以使用echo

echo -e "${txtred}asd${txtwht}"

Here你可以找到更多颜色。

相关问题