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

How to print colored characters using the echo command line

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to use the echo command line to print colored characters, for this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

When writing shell scripts, for some output character highlighting optimization, you can use echo-e for output

Format echo-e "\ 033 [3xmhello\ 033 [0m"

Format echo-e "\ 033 [3xscape 4xmhello\ 033 [0m"

\ 033 [3xm is the ANSI control code, indicating that it is time to start outputting colored characters.

\ 033 [0m is the ANSI control code, indicating the end of the output of colored characters

Note: the character to be output is next to the foreground color (30m). If there is a space in the middle, the output character will also be preceded by a space.

Example:

Echo-e "\ 033 [30mhello\ 033 [0m"

Echo-e "\ 033 [30 * * 43mhello\ 033 [0m"

30 indicates that the foreground is black.

31 means the foreground is red.

32 indicates the foreground is green.

33 indicates a yellow foreground.

34 means the foreground is blue.

35 means the foreground is purple.

36 indicates a light blue foreground.

37 means the foreground is gray.

40 indicates that the background is black.

41 means the background is red.

42 means the background is green.

43 indicates that the background is yellow.

44 indicates the background is blue.

45 indicates that the background is purple.

46 indicates a light blue background.

47 indicates that the background is gray.

This is the answer to the question about how to use the echo command line to print colored characters. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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: 235

*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