How to get osx shell script to show colors in echo

nycynik picture nycynik · Feb 28, 2015 · Viewed 32.3k times · Source

I'm trying to add color output to my errors in a bash script that I have running on a mac. The problem is the colors are not working. I created the simplest of scripts to demonstrate that it does not work:

#!/bin/bash

echo -e "\e[1;31m This is red text \e[0m"

However, when i run it, I see no colors at all, as shown in this image. The color output of the ls command is working fine however.

enter image description here

Answer

guapolo picture guapolo · May 21, 2016

Use \033 or \x1B instead of \e to represent de <Esc> character.

echo -e "\033[1;31m This is red text \033[0m"

See http://misc.flogisoft.com/bash/tip_colors_and_formatting