Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux uses the echo command to output the appropriate color

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

We often use the echo command in shell scripts, and the echo-e option can also render the text output and add descriptive visual effects in addition to the transfer character.

The structure of its output is like this

Example

"\ 033 [32m xxx\ 033 [0m"\ 033 [32m output\ 033 [0m")

\ 033 is equivalent to the color format, this is fixed, [32 means green, the middle is the output content, [0m "means the end, it can be understood that the front 32m can be changed, and the color format below is the color format. You can output any color you want.

The output is green with the output in the middle

[root@zhaocheng] # echo-e "\ 033 [32m This is a colorful world\ 033 [0m" This is a colorful world

That is, you can change the color of the font by changing the corresponding number.

30: black

31: red

32: green

33: yellow

34: blue

35: purple

36: light blue

37: Gray

In addition to changing the color of the output, you can also modify its background color

The format is like this.

Add 41 to the original format; basic format "\ 033 [32m xxx\ 033 [0m" background format "\ 033 [41bot 32m xxx\ 033 [0m"

The format has not changed, just adding numbers to the original basis.

Background color system

40: black

41: red

42: green

43: yellow

44: blue

45: purple

46: light blue

47: Gray

That is, the basic color number is from 30 to 37, the background color is from 40 to 47, and the color number is the same, but the numbers are different.

"\ 033 [32m xxx\ 033 [0m" belongs to the ansi control code, which not only controls the color, but also provides some other functions.

033 [0m turns off all attributes, that is to say, the previous control code will be invalid, of course, this 0 can also be ignored

This 0m can also be omitted.

\ 033 [1m set high brightness

\ 033 [4m underline

\ 033 [5m flicker

\ 033 [7m reflected, displayed in black and white background

\ 033 [8m blanking, character color is the same as background color

30m-37m is used to set the character color

40;-47; is used to set the background color

\ 033 [K is clear from the cursor to the end of the line

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report