Previous Next Contents

4. Which colours is there to choose from?

This shell script (thanks to the many who sent me bash versions) shows all standard colour combinations on the current console. If no colours appear, your console does not support ANSI colour selections.

#!/bin/bash
# Display ANSI colours.
#
esc="\033["
echo -n " _ _ _ _ _40 _ _ _ 41_ _ _ _42 _ _ _ 43" 
echo "_ _ _ 44_ _ _ _45 _ _ _ 46_ _ _ _47 _"
for fore in 30 31 32 33 34 35 36 37; do
  line1="$fore  " 
  line2="    "
  for back in 40 41 42 43 44 45 46 47; do
    line1="${line1}${esc}${back};${fore}m Normal  ${esc}0m"
    line2="${line2}${esc}${back};${fore};1m Bold    ${esc}0m"
  done
  echo -e "$line1\n$line2"
done

The foreground colour number is listed to the left, and the background number in the box. If you want bold characters you add a "1" to the parameters, so bright blue on white would be "37;44;1". The whole ANSI selection sequence is then

ESC [ 3 7 ; 4 4 ; 1 m

Note: The background currently cannot be bold, so you cannot have yellow (bold brown) as anything but foreground. This is a hardware limitation.

The colours are:
        0 - black    4 - blue           3# is foreground
        1 - red      5 - magenta        4# is background
        2 - green    6 - cyan
        3 - yellow   7 - white          ;1 is bold


Previous Next Contents