Linux shell script output with color text

Source: Internet
Author: User

Linux shell script output with color text

The color of the text terminal can be generated by using the ANSI unconventional character sequence.

Example: "Echo-e \033[44;37;5m BLUE \033[0m"

"Echo-e \033[44;37;5m BLUE \033[0m BLACK"


The area that needs to be modified is the red underlined part, where [the contents of the ***m section are replaced by the following number, and the content that you want to paint is later.


The above command set the function as follows: The background color is blue, the foreground color is white, the font blinks, the output character "blue", and then reset the screen to the default settings, the output character "BLACK". "E" is an optional option for the command echo, which is used to activate the parser for special characters. "\033" guides the non-regular character sequence. "M" means to set the property and then end the unconventional character sequence, the real valid characters in this example are "44;37;5" and "0". modifying "44;37;5" can produce combinations of different colors, which are not related to the sequence of values and encodings.


The encoding you can choose is as follows:

"The foreground is the font color;

The background is similar to the shading of the text, or it is called the back color. 】

Coded Color/action

0 Reset properties to default settings

1 setting Bold

2 Set half brightness (simulates color of color display)

4 Set underline (simulates color of color display)

5 Setting flashes

7 Setting the reverse image

22 Setting general Density

24 Turn underline off

25 Flashing off

27 Turn off reverse image

30 setting Black foreground

31 set Red foreground

32 Setting Green foreground

33 Setting Brown foreground

34 Set Blue Foreground

35 Setting Purple foreground

36 Setting the Cyan foreground

37 Setting White foreground

38 underline on the default foreground color

39 Turn the underline off on the default foreground color

40 Setting a black background

41 Setting the red background

42 Setting the green background

43 Setting the brown background

44 Setting the blue background

45 Setting purple Background

46 Setting the Cyan background

47 Setting a white background

49 Setting the default black background


The following is an example of a system (not researched, content to be modified)

#定义终端颜色

function Def_colors ()

{

#特性

normal=& #39;\033[0m& #39;; bold=& #39;\033[lm& #39;;

dim=& #39;\033[2m& #39;; under=& #39;\033[4m& #39;;

italic=& #39;\033[3m& #39;; noitalic=& #39;\033[23m& #39;; blink=& #39;\033[5m& #39;;

reverse=& #39;\033[7m& #39;; conceal=& #39;\033[8m& #39;; nobold=& #39;\033[22m& #39;;

nounder=& #39;\033[24m& #39;; noblink=& #39;\033[25m& #39;;

#前景

black=& #39;\033[30m& #39;; red=& #39;\033[31m& #39;;

green=& #39;\033[32m& #39;; yellow=& #39;\033[33m& #39;;

blue=& #39;\033[34m& #39;; magenta=& #39;\033[35m& #39;;

cyan=& #39;\033[36m& #39;; white=& #39;\033[37m& #39;;


#背景

bblack=& #39;\033[40m& #39;; bred=& #39;\033[41m& #39;;

bgreen=& #39;\033[42m& #39;; byellow=& #39;\033[43m& #39;;

bblue=& #39;\033[44m& #39;; bmagenta=& #39;\033[45m& #39;;

bcyan=& #39;\033[46m& #39;; bwhite=& #39;\033[47m& #39;;

}

Def_colors</pre>


This article from "Auspicious Doll" blog, reproduced please contact the author!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.