How to Color Your Terminal Text in Bash

Color your terminal text to make your scripts look better.


Coloring your Terminal script is by no means necessary, but it will make your scripts look better. In Bash, it is possible to change your echo statements to different colors to make the experience a bit more pleasant.

Compare these two images, although they are bad examples. Colored output is often much easier to look at.

colored output vs normal output

It’s actually quite simple to add colored text, all you have to do is add some escape sequences. Here is a summary of some of the most popular ones:

COLOR_RED="\033[0;31m"
COLOR_RED_LIGHT="\033[1;31m"

COLOR_GREEN="\033[0;32m"
COLOR_GREEN_LIGHT="\033[1;32m"

COLOR_ORANGE="\033[0;33m"
COLOR_YELLOW="\033[1;33m"

COLOR_BLUE="\033[0;34m"
COLOR_BLUE_LIGHT="\033[1;34m"

COLOR_PURPLE="\033[0;35m"
COLOR_PURPLE_LIGHT="\033[1;35m"

COLOR_CYAN="\033[0;36m"
COLOR_CYAN_LIGHT="\033[1;36m"

COLOR_GRAY="\033[1;30m"
COLOR_GRAY_LIGHT="\033[0;37m"

COLOR_BLACK="\033[0;30m"
COLOR_WHITE="\033[1;37m"

COLOR_END="\033[0m"

All you have to do in the echo statement is to add an -e flag and your escape sequence. Also, do not forget to end your color, or else it will continue until another color is presented.

echo -e "${COLOR_GREEN}Success!${COLOR_END}"

The summary was picked from this great article.