• 4

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   when using it:

~ $ 
~ $ echo "

~ $ echo -e "

~ $ 

But when I try to use e, I get this:

~ $ echo -e "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.

I cannot tell you why it does not support that argument (you may have to ask the programmers about that). I only know that on my linux box, I get this:

$ /bin/echo --help
Usage: /bin/echo [SHORT-OPTION]... [STRING]...
  or:  /bin/echo LONG-OPTION
Echo the STRING(s) to standard output.

  -n             do not output the trailing newline
  -e             enable interpretation of backslash escapes
  -E             disable interpretation of backslash escapes (default)
      --help     display this help and exit
      --version  output version information and exit

If -e is in effect, the following sequences are recognized:
*emphasized text*
  NNN   the character whose ASCII code is NNN (octal)
  \     backslash
       alert (BEL)
  c     produce no further output
       form feed
     new line
     carriage return
  	     horizontal tab
       vertical tab

NOTE: your shell may have its own version of echo, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

Report echo bugs to [email protected]
GNU coreutils home page: <>
General help using GNU software: <>
Report echo translation bugs to <>
  • this does not mention e escapes
  • it says that it is /bin/echo from gnu coreutils. As apple changes the source of their unix-system components from time to time (e.g. move from zsh to bash), check if there was a change for /bin/echo between Leopard and Snow Leopard. If it is gnu, you can ask the people at why they choose not to include those sequences.

As for workarounds (thats more interesting): Not using /bin/echo, but bash's builtin echo works on linux boxes. If they changed to a bash without builtin echo (or something even more obscure), you could also try this not widely known feature of your shell (works at least in bash and zsh):

$ echo $'e[34m''COLORS'
  • 0
Reply Report


Related Questions

Trending Tags