When I try to print out some colored text using ANSI escape sequences via the built-in echo
command, it seems that the \e
escape sequence in the string I provide is interpreted literally instead of as the "escape" it's supposed to represent. This only happens in Snow Leopard -- the examples below work as intended in Leopard.
Apparently echo
does support the -e
switch since it correctly interprets \n
when using it:
~ $
~ $ echo "\n"
\n
~ $ echo -e "\n"
~ $
But when I try to use \e
, I get this:
~ $ echo -e "\e[34mCOLORS"
\e[34mCOLORS
~ $
Like I said, in Leopard, the above would give me the string "COLORS" in color.
Does anyone know of a reason why this might be an intended change? How about a workaround for printing ANSI escape sequences from Bash scripts on Snow Leopard?
The Bash shell version on my Leopard machine is 3.2.17(1)-release
and 3.2.48(1)-release
on my Snow Leopard machine.