Skip to main content

Linux Bash/Shell Coloring

You can beautify your BASH script by coloring its output. Use ANSI escape sequences to set text properties such as foreground and background colors.

Syntax

echo -e "\e[COLORmSample Text\e[0m"
OptionDescription
-eEnabling the interpretation of backslash escapes
\e[Start of color changes
COLORmColor code + 'm' at the end
\e[0mEnd of color changes

Example

Green Text
echo -e "\e[32mGreen Text\e[0m"

ANSI — Color Codes

ColorForeground CodeBackground Code
Black3040
Red3141
Green3242
Brown3343
Blue3444
Purple3545
Cyan3646
Light Gray3747

There are some differences between colors when combining colors with the Bold Formating Code

ColorForeground CodeBackground Code
Dark Gray1;301;40
Light Red1;311;41
Light Green1;321;42
Yellow1;331;43
Light Blue1;341;44
Light Purple1;351;45
Light Cyan1;361;46
White1;371;47

Example

echo -e "\e[1;34mLight Blue Text\e[0m"

ANSI - Formating Codes

The ANSI codes also lets you control the way characters are displayed on the screen

ANSI CodeDescription
0Normal
1Bold
4Underlined
5Blinking
7Reverse video

Examples

echo -e "\e[1mBold Text\e[0m"
echo -e "\e[3mUnderlined Text\e[0m"