How to work with text colors on Linux
January 6, 2025

How to work with text colors on Linux

$ echo -e $GREEN I $YELLOW love $BLUE color $NORMAL
I love color

The -e option of the echo directive is described in the man page as “enabling the interpretation of backslash escapes”, but it also allows these color options to work.

Of course, how prominent the letters are will depend on the background color in the viewport, but you should see the chosen color. The NORMAL setting returns the font color to its default value so that you don’t end up displaying all text in the last color used.

To avoid having two whitespace characters between words in a phrase, use the following command instead:

$ echo -e $GREEN I$YELLOW love$BLUE color$NORMAL
I love color

If you want other colors, you can add them to your color profile:

LTGREEN="\033[32m"
LTYELLOW="\033[33m"
LTBLUE="\033[34m"
LTMAGENTA="\033[35m"
LTCYAN="\033[36m"
LTWHITE="\033[37m"

NOTE: If you are having trouble and the text color is not returning to normal, issue the following command to resolve the issue.

$ echo -e $NORMAL

background color

You can also use the color settings to change the background color of your screen. The command shown below will change the background color after issuing the command, leaving the space above it as the previous background color.

2024-12-18 17:32:25

Leave a Reply

Your email address will not be published. Required fields are marked *