Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to print colored characters using the echo command line

Shulou Source: shulou.com Published: 2022-06-01 08:26:48 11月15日 Update

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.

Tags: Foreground background character output color blue question command more format purple red green yellow black help control solution easy easy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Shulou Technology MariaDB NVidia