How to get osx shell script to show colors in echo How to get osx shell script to show colors in echo bash bash

How to get osx shell script to show colors in echo


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


OSX ships with an old version of Bash that does not support the \e escape character. Use \x1B or update Bash (brew install bash).

Even better, though, would be to use tput.


In script files printf could be yet another option, you have to add trailing "\n" though.

#!/bin/bashecho -e "\e[31mOutput as is.\e[m"printf "\e[32mThis is green line.\e[m\n"printf "\e[33;1m%s\n" 'This is yellow bold line.'

Tested on macOS High Sierra 10.13.6:

% /bin/bash --versionGNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)Copyright (C) 2007 Free Software Foundation, Inc.