Table of Contents

BASH - Colors - 3 and 4-bit Colors

8 Colors.


Format

ESC[ 0;⟨n⟩ m Select normal color
ESC[ 1;⟨n⟩ m Select bright color

where n is:


Red Example

echo -e "\033[0;31mThis is in RED"

NOTE: This is made up of:

  • \033 - Represents the ESC key.
  • [0; - Normal color.
  • [31m] - Red; from color table.

Bright Red Example

echo -e "\033[1;31mThis is in BRIGHT RED"

NOTE: This is made up of:

  • \033 - Represents the ESC key.
  • [1; - Bright color.
  • [31m] - Red; from color table. Notice this is NOT using the bright numbers from the color table.

Bright colors can be used simply by using a 1 after the ESC instead of a 0.

  • Some older systems may not support this, so in this case use the alternative number from the color table;
echo -e "\033[0;91mThis is in BRIGHT RED"
  • Here the 31m has been changed to 91m.

Red Blue

echo -e "\033[0;31mThis is in RED\033[0;34mThis is in Blue"

ANSI Rainbow

for (( i = 30; i < 38; i++ )); do echo -e "\033[0;"$i"m Normal: (0;$i); \033[1;"$i"m Bright: (1;$i)"; done