Bash: Outputting text in color for readability

If you need to call attention to a message within your script, a splash of color is often the best way to get noticed in the sea of monochrome text.

The standard ANSI escape codes are supported at most consoles, and in its simplest form can be used like this:

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

echo -e "${GREEN}OK${NC} you just did something great!"
echo -e "${RED}FAIL${NC} oops, there was an error in processing"

Which would output text that looks like:

OK you just did something great!
FAIL oops, there was an error in processing

The “-e” is necessary for echo to allow backslashes.  A list of foreground colors can be found here.  A more comprehensive list of foreground/background colors is listed on wikipedia.

REFERENCES

stackoverflow, changing the output color of echo

shellhacks, bash colors

howtogeek, color your PS1 prompt

linuxnix.com, control commands within PS1 prompt

NOTES

coloring the console prompt, “\h” is hostname, “\u” user, “\p” path

export PS1="\[\033[01;32m\]\h\[\033[0m\] ${debian_chroot:+($debian_chroot)}\u:\w\$ "