How to change text color & background in mac terminal? How to change text color & background in mac terminal? unix unix

How to change text color & background in mac terminal?


Multiple SGR options can be chained together, and in fact more compactly than you've been trying. The SGR syntax takes the general form of:

\e[ options m

where options can consist of one* or more numbers separated by semicolons, which can include a number of things, but especially:

  • 1: bold
  • 30 – 37: set foreground color 0 – 7 (black, red, green, yellow, blue, magenta, cyan, white)
  • 40 – 47: set background color 0 – 7 (ditto)
  • 90 – 97: set foreground color 8 – 15 (bright versions of 0 – 7; "bright black" is a dark gray)
  • 100 – 107: set background color 8 – 15 (ditto)

In your case, red text on a white background would be \e[31;47m.


(*: Or no numbers at all, in which case it resets all graphical options.)