Output colored text in the shell using the echo command
Name
echo-Displays a line of text
Profile
echo [Options] ... [String] ...
Describe
Outputs a string to the standard output.
-N does not output line breaks
-E Open backslash ESC escape
-e Suppress backslash ESC escape (default)
--HELP Display Help
--version Display version
Note You must have the-e option for the output color.
And then say the point: ANSI control code is used in the output of color text.
-E to open escape in Echo
\e or \ 033来 output ESC symbol
Format color: \e[background color, foreground colour, highlight m
\033[background color, front color, highlight m
Restore Defaults to \e[0m
Where the background color can be replaced by the following numbers
First parameter:
0 transparent (using terminal color), 1 highlight 40 black, 41 red, 42 green, 43 yellow, 44 blue 45 Violet, 46 cyan
Green, 47 white (grey)
A second parameter:
The foreground color (that is, the colour of the text) can be replaced by the following numbers
30 Black 31 Red, 32 green, 33 yellow, 34 blue, 35 violet, 36 turquoise, 37 white (grey)
A third parameter:
Highlight is 1, not highlight is 0
The fourth parameter is m:
Note that the string is followed by M.
Instance:
1, output red font ABC, background color unchanged, the following three effects are the same
ECHO-E ' \033[0;31;1m ABC \033[0m '
ECHO-E "\e[1;31m ABC \e[0m"
ECHO-E "\e[0;31;1m ABC \e[0m"
2, Output * * * Font ABC, red background color, the following three effects the same
ECHO-E ' \033[41;33;1m ABC \033[0m '
ECHO-E "\e[41;33m ABC \e[0m"
ECHO-E "\e[41;33;1m ABC \e[0m"
30 Black 31 Red, 32 green, 33 yellow, 34 blue, 35 violet, 36 turquoise, 37 white (grey)
Echo-e "\e[1;30m Skyapp exist \e[0m"//Black
Echo-e "\e[1;31m Skyapp exist \e[0m"//Red
Echo-e "\e[1;32m Skyapp exist \e[0m"//Green
Echo-e "\e[1;33m Skyapp exist \e[0m"//***
Echo-e "\e[1;34m Skyapp exist \e[0m"//Blue
Echo-e "\e[1;35m Skyapp exist \e[0m"//Purple
Echo-e "\e[1;36m Skyapp exist \e[0m"//Turquoise
Echo-e "\e[1;37m Skyapp exist \e[0m"//White (grey)
Embedded in the method:
Echo-e "^[[1;30m Skyapp exist ^[[0m"//Black
Echo-e "^[[1;31m Skyapp exist ^[[0m"//Red
Echo-e "^[[1;32m Skyapp exist ^[[0m"//Green
Echo-e "^[[1;33m Skyapp exist ^[[0m"//***
Echo-e "^[[1;34m Skyapp exist ^[[0m"//Blue
Echo-e "^[[1;35m Skyapp exist ^[[0m"//Purple
Echo-e "^[[1;36m Skyapp exist ^[[0m"//Turquoise
Echo-e "^[[1;37m Skyapp exist ^[[0m"//White (grey)
######################################
[email protected] script]# cat yansh.sh
#!/bin/sh
ECHO-E ' \033[0;31;1m ABC \033[0m '
ECHO-E "\e[1;31m ABC \e[0m"
ECHO-E "\e[0;31;1m ABC \e[0m"
###############################
ECHO-E ' \033[41;33;1m ABC \033[0m '
ECHO-E "\e[41;33m ABC \e[0m"
ECHO-E "\e[41;33;1m ABC \e[0m"
###############################
Echo-e "\e[1;30m Skyapp exist \e[0m"
Echo-e "\e[1;31m Skyapp exist \e[0m"
Echo-e "\e[1;32m Skyapp exist \e[0m"
Echo-e "\e[1;33m Skyapp exist \e[0m"
Echo-e "\e[1;34m Skyapp exist \e[0m"
Echo-e "\e[1;35m Skyapp exist \e[0m"
Echo-e "\e[1;36m Skyapp exist \e[0m"
Echo-e "\e[1;37m Skyapp exist \e[0m"
Note: The input method of the ^[is the CTRL + V key, and then the ESC key
And then give some more powerful script functions
1 CFont
#by Zuoyang http://hi.baidu.com/test/
CFont ()
{
while (($#!=0))
Do
Case $ in
-B)
Echo-ne "";
;;
-T)
Echo-ne "\ t";
;;
-N) echo-ne "\ n";
;;
-black)
Echo-ne "\033[30m";
;;
-red)
Echo-ne "\033[31m";
;;
-green)
Echo-ne "\033[32m";
;;
-yellow)
Echo-ne "\033[33m";
;;
-blue)
Echo-ne "\033[34m";
;;
-purple)
Echo-ne "\033[35m";
;;
-cyan)
Echo-ne "\033[36m";
;;
-white|-gray) Echo-ne "\033[37m";
;;
-reset)
Echo-ne "\033[0m";
;;
-H|-HELP|--HELP)
echo "Usage:cfont-color1 Message1-color2
Message2 ... ";
echo "eg:cfont-red [-blue message1
Message2-red] ";
;;
*)
Echo-ne "$"
;;
Esac
Shift
Done
}
How to use it is
CFont-Color String ...
Such as:
Cfont-cyan ABC
Note that you need to add the-N option when you use the line. You want to restore the default to join the-reset option.
#####################################################################
#####################################################################
#####################################################################
#####################################################################
echo Display in shell script with color display, echo display with color, need to use parameter-E
The format is as follows:
Echo-e "\033[word background color; text color m string \033[0m"
For example:
Echo-e "\033[41;36m something here \033[0m"
Where 41 of the position represents the background, 36 of the position is the color of the word
Note:
1, the word background color and the text color is in English ""
2. There is a m behind the text color
3, before and after the string can have no space, if any, the output is also a space
Here is the corresponding word and background color, you can try to find out the different color collocation
Cases
Echo-e "\033[31m Red word \033[0m"
ECHO-E "\033[34m * * * * character \033[0m"
Echo-e "\033[41;33m Red bottom yellow word \033[0m"
Echo-e "\033[41;37m Red bottom White \033[0m"
Word Color: 30-–37
Echo-e "\033[30m Black character \033[0m"
Echo-e "\033[31m Red word \033[0m"
Echo-e "\033[32m Green word \033[0m"
ECHO-E "\033[33m * * * * character \033[0m"
Echo-e "\033[34m Blue word \033[0m"
Echo-e "\033[35m Purple word \033[0m"
Echo-e "\033[36m sky blue Word \033[0m"
Echo-e "\033[37m White character \033[0m"
Word background color range: 40-–47
Echo-e "\033[40;37m Black Bottom White \033[0m"
Echo-e "\033[41;37m Red bottom White \033[0m"
Echo-e "\033[42;37m Green bottom White \033[0m"
Echo-e "\033[43;37m Yellow \033[0m"
Echo-e "\033[44;37m Blue bottom White \033[0m"
Echo-e "\033[45;37m Purple \033[0m"
Echo-e "\033[46;37m sky blue Bottom White \033[0m"
Echo-e "\033[47;30m black character \033[0m on white background"
Last Face Control option description
\33[0m Close All Properties
\33[1m Setting High brightness
\33[4m Underline
\33[5m Flashing
\33[7M Reverse Display
\33[8m blanking
\33[30m-\33[37m Setting the foreground color
\33[40m-\33[47m Setting the background color
\33[na the cursor to move n rows
\33[NB cursor down n rows
\33[NC cursor right shifts n rows
\33[nd cursor left n rows
\33[Y;XH Setting the cursor position
\33[2J Clear Screen
\33[k clears the contents from the cursor to the end of the line
\33[s Save Cursor position
\33[u Restore cursor Position
\33[?25l Hide Cursor
\33[?25h Display cursor
[email protected] script]# cat yansh.sh
#/bin/sh
Echo-e "\033[31m Red word \033[0m"
ECHO-E "\033[34m * * * * character \033[0m"
Echo-e "\033[41;33m Red bottom yellow word \033[0m"
Echo-e "\033[41;37m Red bottom White \033[0m"
#----------------------------------------
Echo-e "\033[30m Black character \033[0m"
Echo-e "\033[31m Red word \033[0m"
Echo-e "\033[32m Green word \033[0m"
ECHO-E "\033[33m * * * * character \033[0m"
Echo-e "\033[34m Blue word \033[0m"
Echo-e "\033[35m Purple word \033[0m"
Echo-e "\033[36m sky blue Word \033[0m"
Echo-e "\033[37m White character \033[0m"
#----------------------------------------
Echo-e "\033[40;37m Black Bottom White \033[0m"
Echo-e "\033[41;37m Red bottom White \033[0m"
Echo-e "\033[42;37m Green bottom White \033[0m"
Echo-e "\033[43;37m Yellow \033[0m"
Echo-e "\033[44;37m Blue bottom White \033[0m"
Echo-e "\033[45;37m Purple \033[0m"
Echo-e "\033[46;37m sky blue Bottom White \033[0m"
Echo-e "\033[47;30m black character \033[0m on white background"
#----------------------------------------
This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1701282
echo Color output in shell